You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 03:30:57