【发布时间】:2017-07-06 01:41:20
【问题描述】:
我开发了一个闪亮的仪表板,我有几个通过反应式文件阅读器导入的数据框等。我还添加了一个“生成 PDF”按钮,在我的 ui.R 代码中使用 downloadButton()。我的 server.R 代码实现了 downloadHandler() 来处理该请求。
在我的 Windows 桌面上,这一切都完美无缺。我希望它在我设置的 Linux 服务器上运行。当然,我不得不修改一些路径,Shiny Server 在这个盒子上以 root 身份运行。当我在 Linux 服务器上运行的站点上单击“生成 PDF”按钮时,我几乎立即收到 HTTP 500 错误。我自己在 Linux 服务器上手动编译了 pdfReport.Rmd 文件,它运行得很好。
我猜两件事之一:
- 不知何故,数据在 Linux 机器上的传递方式与在 Windows 桌面上的传递方式不同。这可能不太可能,但有可能。
- 我的路径有问题,所以当写入临时文件以开始生成 PDF 时,系统没有能力或不存在写入文件的路径。可能我的 downloadHandler() 代码在某些方面格式不正确。我认为这比 #1 的可能性更高。
这是我的 downloadHandler() 代码:
output$pdfReport <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = reactive({paste0("/srv/shiny-server/itpod/","ITPOD-",Sys.Date(),".pdf")}),
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path("/srv/shiny-server/itpod", "pdfReport.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
params <- list(ilp=updateILP(), ico=updateICO(), sec=updateSecurity(), ppwc=updateWorkPreviousPeriodCompleted(),
pow=updateOngoingWorkCABApproved(), pwcr=updatePlannedWorkCABRequested(), epca=updateEmergencyChangesPendingCABApproval(),
fac=updateFacilities(), drs=updateDRStatus(), ov=updateOperationalEvents(), sl=updateStaffLocations(),
w = updateWeather())
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file, params = params, envir = new.env(parent = globalenv())
)
}
)
我认为路径可能是不可写的,所以我尝试将其更改为 /tmp,但这也不起作用。翻来覆去,我发现当我点击“生成 PDF”按钮时,我得到一个带有“会话”的长 URL:
http://my.url.com:3838/itpod/session/d661a858f5679aba26692bc9b4442872/download/pdfReport?w=
我开始怀疑这是否是问题所在,并且我没有写入当前会话的路径或其他什么?对于 Shiny 来说,这对我来说是一个新领域。就像我说的,在我的桌面上它工作正常,但是一旦我将它部署到 Linux 服务器,它就不能正常工作。任何帮助将非常感激。提前致谢!
【问题讨论】:
标签: shiny shiny-server shinydashboard