更新:我添加了以下解决方案
一点背景:我在Ubuntu精确服务器上运行Shiny server v1.5。基本上我有一个rmarkdown页面,允许用户使用一些参数,然后有一个下载按钮,使用闪亮生成文档,如下所示:
```{r,echo=FALSE}
downloadHandler(
filename = "report.pdf",
content = function(file) {
knitr::knit2pdf("report.Rnw",envir=environment())
file.rename(normalizePath('report.pdf'), file)
}
)
```
Shiny应用程序在我的本地计算机上运行良好,但在服务器上崩溃。更具体地说,r markdown网页工作正常,但是一旦我点击下载按钮,应用程序在大约30秒后崩溃。服务器日志指示套接字超时错误:
[2016-02-24 03:38:52.240] [INFO] shiny-server - Starting listener on 0.0.0.0:3838
[2016-02-24 03:49:30.183] [ERROR] shiny-server - Uncaught exception: Error: socket hang up
[2016-02-24 03:49:30.184] [ERROR] shiny-server - Error: socket hang up
at createHangUpError (_http_client.js:215:15)
at Socket.socketCloseListener (_http_client.js:247:23)
at Socket.emit (events.js:129:20)
at TCP.close (net.js:485:12)
[2016-02-24 03:49:30.184] [INFO] shiny-server - Stopping listener on 0.0.0.0:3838
[2016-02-24 03:49:30.185] [INFO] shiny-server - Shutting down worker processes (with notification)
/opt/shiny-server/lib/main.js:364
throw err;
^
Error: socket hang up
at createHangUpError (_http_client.js:215:15)
at Socket.socketCloseListener (_http_client.js:247:23)
at Socket.emit (events.js:129:20)
at TCP.close (net.js:485:12)
这个pdf需要很长时间才能生成(大约五分钟),所以我怀疑我错过了一些超时参数。这就是我在闪亮配置中所做的:
run_as shiny;
app_init_timeout 999999;
app_idle_timeout 999999;
# Define a server that listens on port 3838
server {
listen 3838;
....
}
......但无济于事,因为我仍然收到错误。任何建议将不胜感激!
正如@daattali所提到的,你不可能在downloadButton中花费那么长的时间,更改服务器设置不会改变任何事情。所以我最终分裂了这一代和下载两部分功能如下:
```{r, echo=FALSE}
shinyApp(
ui = fluidPage(
fluidRow(
column(2,
conditionalPanel(
condition = "!$('makeReport').hasClass('shiny-busy')",
actionButton("makeReport","Generate Report",icon=icon("file"))
)
),
column(4,
conditionalPanel(
condition = "!$('makeReport').hasClass('shiny-busy')",
uiOutput("downloadButton")
#downloadButton("downloadReport", "Download Report")
)
)
)
),
server = function(input, output) {
output$download_button <- renderUI({
downloadButton("downloadReport", "Download Results")
})
makeReportAction <- eventReactive(input$makeReport, {
...
knitr::knit2pdf("report.Rnw",envir=globalenv())
})
output$downloadButton <- renderUI({
makeReportAction() #only appear after first click on generate
downloadButton("downloadReport", "Download Report")
})
output$downloadReport <- downloadHandler(
filename = "report.pdf",
content = function(file) {
cat(paste("Does the pdf exist?",file.exists("report.pdf")))
file.rename(normalizePath('report.pdf'), file)
}
)
}
)
```
答案 0 :(得分:1)
可能是上周其他人在Google董事会上问Joe Cheng的问题
https://groups.google.com/forum/#!topic/shiny-discuss/4bL9jFaYly0
下载处理程序看起来有时间限制,因此可能会尝试查看是否可以预先生成文件并仅在单击按钮时提供文件