【问题标题】:My Shiny App works locally but not on shinyapps.io我的 Shiny App 在本地工作,但在 shinyapps.io 上不工作
【发布时间】:2021-08-17 09:44:38
【问题描述】:

我构建了一个简单的闪亮应用。它在本地运行良好,但当我将其加载到 shinyapps.io 时出现错误。

这是错误信息:

发生错误! 发生了错误。检查您的日志或联系应用作者进行澄清。

这是日志的输出。

> rsconnect::showLogs(appName="vaccines-by-country",streaming=TRUE) 
2021-05-25T11:12:17.576509+00:00 shinyapps[4164097]: Registered S3 methods overwritten by 'tibble':
        2021-05-25T11:12:17.576512+00:00 shinyapps[4164097]:   method     from  
2021-05-25T11:12:17.679447+00:00 shinyapps[4164097]:     filter, lag
2021-05-25T11:12:17.576512+00:00 shinyapps[4164097]:   format.tbl pillar
2021-05-25T11:12:17.679448+00:00 shinyapps[4164097]: 
        2021-05-25T11:12:17.576512+00:00 shinyapps[4164097]:   print.tbl  pillar
2021-05-25T11:12:17.679812+00:00 shinyapps[4164097]: The following objects are masked from ‘package:base’:
        2021-05-25T11:12:17.678697+00:00 shinyapps[4164097]: 
        2021-05-25T11:12:17.679814+00:00 shinyapps[4164097]: 
        2021-05-25T11:12:17.678700+00:00 shinyapps[4164097]: Attaching package: ‘dplyr’
2021-05-25T11:12:17.679447+00:00 shinyapps[4164097]: 
        2021-05-25T11:12:17.678701+00:00 shinyapps[4164097]: 
        2021-05-25T11:12:17.679446+00:00 shinyapps[4164097]: The following objects are masked from ‘package:stats’:
        2021-05-25T11:12:17.679812+00:00 shinyapps[4164097]: 
        2021-05-25T11:12:17.679813+00:00 shinyapps[4164097]:     intersect, setdiff, setequal, union
2021-05-25T11:12:17.872130+00:00 shinyapps[4164097]:   88: <Anonymous>
        2021-05-25T11:12:17.863510+00:00 shinyapps[4164097]: Warning: Error in <Anonymous>: error reading from the connection
2021-05-25T11:15:32.272140+00:00 shinyapps[4164097]: Running on host: 16ba9f6b9d17
2021-05-25T11:15:32.276813+00:00 shinyapps[4164097]: R version: 4.0.2
2021-05-25T11:15:32.276812+00:00 shinyapps[4164097]: LANG: en_US.UTF-8
2021-05-25T11:15:32.276832+00:00 shinyapps[4164097]: shiny version: 1.5.0
2021-05-25T11:15:32.276800+00:00 shinyapps[4164097]: Server version: 1.8.6.1
2021-05-25T11:15:32.276876+00:00 shinyapps[4164097]: rmarkdown version: (none)
2021-05-25T11:15:32.276911+00:00 shinyapps[4164097]: knitr version: (none)
2021-05-25T11:15:32.276918+00:00 shinyapps[4164097]: jsonlite version: 1.7.1
2021-05-25T11:15:32.276942+00:00 shinyapps[4164097]: htmltools version: 0.5.1.1
2021-05-25T11:15:32.277087+00:00 shinyapps[4164097]: Using pandoc: /opt/connect/ext/pandoc/2.11
2021-05-25T11:15:32.276869+00:00 shinyapps[4164097]: httpuv version: 1.5.5
2021-05-25T11:15:32.434697+00:00 shinyapps[4164097]: Using jsonlite for JSON processing
2021-05-25T11:15:32.276919+00:00 shinyapps[4164097]: RJSONIO version: (none)
2021-05-25T11:15:32.437887+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:32.437888+00:00 shinyapps[4164097]: Starting R with process ID: '26'
2021-05-25T11:15:32.462208+00:00 shinyapps[4164097]: Listening on http://127.0.0.1:46118
2021-05-25T11:15:32.462207+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:43.997554+00:00 shinyapps[4164097]: Registered S3 methods overwritten by 'tibble':
        2021-05-25T11:15:43.997556+00:00 shinyapps[4164097]:   method     from  
2021-05-25T11:15:43.997556+00:00 shinyapps[4164097]:   format.tbl pillar
2021-05-25T11:15:43.997557+00:00 shinyapps[4164097]:   print.tbl  pillar
2021-05-25T11:15:44.099489+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:44.099492+00:00 shinyapps[4164097]: Attaching package: ‘dplyr’
2021-05-25T11:15:44.099492+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:44.100245+00:00 shinyapps[4164097]: The following objects are masked from ‘package:stats’:
        2021-05-25T11:15:44.100245+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:44.100246+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:44.100246+00:00 shinyapps[4164097]:     filter, lag
2021-05-25T11:15:44.100607+00:00 shinyapps[4164097]: The following objects are masked from ‘package:base’:
        2021-05-25T11:15:44.100608+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:44.100609+00:00 shinyapps[4164097]:     intersect, setdiff, setequal, union
2021-05-25T11:15:44.100609+00:00 shinyapps[4164097]: 
        2021-05-25T11:15:44.285726+00:00 shinyapps[4164097]: Warning: Error in <Anonymous>: error reading from the connection
2021-05-25T11:15:44.293913+00:00 shinyapps[4164097]:   88: <Anonymous>

警告:匿名错误:从连接读取错误

这是我的 ui.R 代码:

library(shiny)
library(dplyr)
library(ggplot2)
library(readr)
df <- read_csv("country_vaccinations.csv.zip")
countries <- df %>% distinct(country)

fluidPage(
        titlePanel("Covid Vaccines by Country by Maria Freydlin"),
        h4("Instructions:"),
        h5("Please select a country from the dropdown list below to view the timeline of total vaccines administered within the last few months."),
        a(href="https://github.com/mariafreydlin/shinyapp/tree/master", 'Link to UI and Server code files'),
        titlePanel("Vaccine Timeline by Country"),   
        
        sidebarLayout(
                sidebarPanel(
                        selectInput( "country", "Country:", choices=countries),
                        hr()
                        
                ),
                mainPanel(
                        plotOutput("vaccinePlot")
                )
        )
)

这是我的 server.R 代码:

library(shiny)
library(dplyr)
library(ggplot2)
library(readr)
df <- read_csv("country_vaccinations.csv.zip")

function(input, output){
        df_total <- reactive({
                df %>%
                        filter(country==input$country)%>%
                        group_by(date) %>%
                        summarise(total = sum(total_vaccinations, na.rm = T))
        })
        
        output$vaccinePlot <- renderPlot({
                ggplot(df_total(), aes(date, total)) + geom_line() +theme_bw()
        })
}

csv.zip 文件与 ui.R 和 server.R 位于同一文件夹中。

有什么想法、建议吗?

【问题讨论】:

  • 当我将所有内容加载到 shinyapps 时,我确定了 csv.zip 文件也包含在内。
  • 如果你清除工作区中的所有变量(例如使用rm(ls = list())),它仍然在本地工作吗?
  • 如果您解压缩并更改代码以读取 .csv 而不是 .zip 会怎样?
  • 是的!在阅读 .csv 之前解压缩为我解决了这个问题!谢谢埃里克!

标签: r shiny shinyapps


【解决方案1】:

按照 Eric 在 cmets 中的建议,我解压缩了 csv.zip 文件并改为读取 .csv。这解决了问题!

file = unzip("country_vaccinations.csv.zip")
df <- read_csv(file)

谢谢!

【讨论】:

    猜你喜欢
    • 2018-06-11
    • 2018-11-24
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 2014-01-02
    相关资源
    最近更新 更多