R语言 ShinyApp在本地工作,但不在www.example.com上shinyapps.io

edqdpe6u  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(117)

我有一个闪亮的应用程序,从数据库中提取NBA统计数据并制作散点图。app.R文件代码如下。您需要从github devtools::install_github("abresler/nbastatR")安装nbaplotR以及nbaplotR if (!require("pak")) install.packages("pak") pak::pak("mrcaseb/nbaplotR")。这个应用程序在我本地运行时可以工作,但在www.example.com上无法shinyapps.io。在shinyapps.io中,图或表都不会显示。我认为shinyapps。io服务器没有正确连接或安装上述软件包。任何帮助将不胜感激!

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)
6rvt4ljy

6rvt4ljy1#

我一直在解决同样的问题几个星期,无法解决它,所以我尝试的最后一件事是手动下载数据作为csv文件,然后上传到ShinyApp。我发现,当你下载所有的数据,它超过1GB,我认为闪亮的应用程序限制您的数据大小为1GB。
也许这可能是问题所在,因为我在另一个包的其他数据上尝试了我的代码,它工作了,但nbastatR没有

相关问题