英文:
ShinyApp works locally but not on shinyapps.io
问题
我有一个闪亮的应用程序,可以从数据库中提取NBA统计数据并制作散点图。 app.R文件的代码如下。 您需要从GitHub安装nbaplotR devtools :: install_github("abresler / nbastatR")
以及nbaplotR如果(!require("pak"))install.packages("pak") pak :: pak("mrcaseb / nbaplotR")
。 当我在本地运行它时,此应用程序有效,但在尝试部署到shinyapps.io时却无法正常运行。 在shinyapps.io上,图表和表格都不显示。 我认为shinyapps.io服务器未能正确连接或安装上述包。 任何帮助将不胜感激!
英文:
I have a shiny app that pulls in NBA statistics from a database and makes a scatterplot. The app.R file code is below. You need to install nbaplotR from github devtools::install_github("abresler/nbastatR")
along with nbaplotR if (!require("pak")) install.packages("pak")
. This app works when I run it locally but not on shinyapps.io when I try to deploy it. In shinyapps.io neither the plot or the table show up. I think the shinyapps.io server is not properly connecting with or installing the above mentioned packages. Any help would be greatly appreciated!
pak::pak("mrcaseb/nbaplotR")
library(devtools)
library(shiny)
library(ggplot2)
library(nbastatR)
library(tidyverse)
library(nbaplotR)
library(nbapalettes)
library(forcats)
library(ggpubr)
library(DT)
library(ggpath)
ui <- fluidPage(
titlePanel("NBA team stats"),
sidebarLayout(
sidebarPanel(
selectInput("x", "X-axis stat",
choices = c("gp", "pctWins", "fgm", "fga", "pctFG",
"fg3m", "fg3a", "pctFG3", "pctFT",
"gpRank", "pctWinsRank", "minutesRank", "fgmRank",
"fgaRank", "pctFGRank", "fg3mRank", "fg3aRank",
"pctFG3Rank", "pctFTRank", "fg2m", "fg2a",
"pctFG2", "wins", "losses", "minutes", "ftm",
"fta", "oreb", "dreb", "treb", "ast", "tov", "stl",
"blk", "blka", "pf", "pfd", "pts", "plusminus",
"winsRank", "lossesRank", "rankFTM", "rankFTA",
"orebRank", "drebRank", "trebRank", "astRank",
"tovRank", "stlRank", "blkRank", "blkaRank", "pfRank",
"pfdRank", "ptsRank", "plusminusRank", "Name_abbreviation"),
selected = "fgm",
multiple = FALSE
),
selectInput("y", "Y-axis stat",
choices = c("gp", "pctWins", "fgm", "fga", "pctFG",
"fg3m", "fg3a", "pctFG3", "pctFT",
"gpRank", "pctWinsRank", "minutesRank", "fgmRank",
"fgaRank", "pctFGRank", "fg3mRank", "fg3aRank",
"pctFG3Rank", "pctFTRank", "fg2m", "fg2a",
"pctFG2", "wins", "losses", "minutes", "ftm",
"fta", "oreb", "dreb", "treb", "ast", "tov", "stl",
"blk", "blka", "pf", "pfd", "pts", "plusminus",
"winsRank", "lossesRank", "rankFTM", "rankFTA",
"orebRank", "drebRank", "trebRank", "astRank",
"tovRank", "stlRank", "blkRank", "blkaRank", "pfRank",
"pfdRank", "ptsRank", "plusminusRank"),
selected = "pctFG",
multiple = FALSE
),
),
mainPanel(
plotOutput("logoscatter"),
DT::DTOutput("Table")
)
)
)
server <- function(input, output) {
#Getting team logos for the plots
Names_abbrev <- valid_team_names()
Names_abbrev[2] <- Names_abbrev[3]
Names_abbrev[3] <- "BKN"
Names_abbrev[26] <- "SAC"
Names_abbrev[27] <- "SA"
Sys.setenv(VROOM_CONNECTION_SIZE=500072)
team_stats_general <- unique(nbastatR::teams_players_stats(seasons = 2023,
types = "team",
tables = "general"))
team_stats_df <- as.data.frame(team_stats_general[[7]])
team_stats_df$Name_abbreviation <- Names_abbrev
team_stats_df$Name_abbreviation <- as.factor(team_stats_df$Name_abbreviation)
team_stats_df <- team_stats_df[,c(10, 12:ncol(team_stats_df))]
output$logoscatter <- renderPlot({
req(input$x, input$y)
plot_scale_x <- if (input$x %in% c("pctWins", "pctFG", "pctFG3", "pctFT", "pctFG2")){
scale_x_continuous(labels = scales::percent_format(accuracy = 1))
}else{
scale_x_continuous()
}
plot_scale_y <- if (input$y %in% c("pctWins", "pctFG", "pctFG3", "pctFT", "pctFG2")){
scale_y_continuous(labels = scales::percent_format(accuracy = 1))
}else{
scale_y_continuous()
}
p1 <- ggplot(data = team_stats_df)+
geom_smooth(aes_string(x = input$x, y = input$y),
method = "lm", se = F, color = "black", linetype = "dashed")+
geom_nba_logos(aes_string(x = input$x, y = input$y, team_abbr = "Name_abbreviation"),
width = 0.075, height = 0.075)+
stat_cor(aes_string(x = input$x, y = input$y, label="..rr.label.."),
label.x.npc = 0.85, label.y.npc = 0.02, size = 6)+
plot_scale_x+
plot_scale_y+
ylab(input$y)+
xlab(input$x)+
theme_bw()+
theme(plot.title = element_text(hjust = 0.5),
text = element_text(size = 18))
p1
})
output$Table <- renderDT({
team_stats_df
})
}
shinyApp(ui = ui, server = server)
答案1
得分: 1
我已经困扰同一个问题好几周了,但一直无法解决。最后我尝试了手动下载数据作为 CSV 文件,然后在 ShinyApp 上上传。我发现当你下载所有数据时,文件超过了1GB,而我认为 Shiny 应用限制了数据大小为1GB。
也许这就是问题所在,因为我尝试了另一个包的数据,它可以正常工作,但是 nbastatR 却不行。
英文:
I have been working on the same problem for weeks and couldn't solve it so the last thing I tried was downloading the data manually as csv file and then upload on ShinyApp. And I figured out that when you download all the data, it goes over 1GB, and I think shiny app limits your data size by 1GB.
Maybe that could be the problem because I tried my code on other data from another package and it worked but nbastatR didn't
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论