ShinyApp无法发布至shinyapps.io问题求助
ShinyApp发布至shinyapps.io启动失败排查与解决
本地在RStudio中运行正常的ShinyApp,发布至shinyapps.io后浏览器持续显示启动错误:
An error has occurred
The application failed to start.
exit status 1
原问题代码(未声明依赖库)
dat <- read_csv(url("https://www.dropbox.com/s/uhfstf6g36ghxwp/cces_sample_coursera.csv?raw=1")) %>% select(c("pid7","ideo5")) %>% drop_na() ui <- fluidPage(sidebarLayout( sliderInput(inputId = "ideo5", label = "Select Five Point Ideology (1=Very liberal, 5=Very conservative)", min = min(dat[,2]), max = max(dat[,2]), value = 3), plotOutput("distPlot"))) server <- function(input, output) { output$distPlot <- renderPlot({ c <- ggplot(dat %>% filter(ideo5 == input$ideo5), aes(pid7)) + labs(x = "7 Point Party ID, 1=Very D, 7=Very D") c + geom_bar() }) } shinyApp(ui = ui, server = server)
问题根源
代码未明确声明依赖的R包,导致shinyapps.io服务器无法自动加载运行所需的库,进而引发启动失败。
修正后的完整代码
在代码开头添加依赖包加载语句后即可正常发布:
library(shiny) library(tidyverse) library(ggplot2) dat <- read_csv(url("https://www.dropbox.com/s/uhfstf6g36ghxwp/cces_sample_coursera.csv?raw=1")) %>% select(c("pid7","ideo5")) %>% drop_na() ui <- fluidPage(sidebarLayout( sliderInput(inputId = "ideo5", label = "Select Five Point Ideology (1=Very liberal, 5=Very conservative)", min = min(dat[,2]), max = max(dat[,2]), value = 3), plotOutput("distPlot"))) server <- function(input, output) { output$distPlot <- renderPlot({ c <- ggplot(dat %>% filter(ideo5 == input$ideo5), aes(pid7)) + labs(x = "7 Point Party ID, 1=Very D, 7=Very D") c + geom_bar() }) } shinyApp(ui = ui, server = server)
内容的提问来源于stack exchange,提问作者Stella Devito
相关产品推荐
相关产品推荐

