我想从闪亮服务器上的闪亮应用程序生成pdf报告。它在我的计算机上运行良好。 我尝试放在闪亮的服务器上,但是当我想生成报告时,我得到的是Firefox“找不到文件”页面,而不是pdf。
我使用以下代码显示:https://shiny.rstudio.com/articles/generating-reports.html 我也尝试直接使用.Rmd文件,而不是将其复制/粘贴到temp目录中,但是我遇到了同样的错误。
我的服务器文件:
output$pdfGen <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "rapport_preci.pdf",
content = function(file) {
withProgress(message = "Génération du pdf en cours", value = 0,{
src <- normalizePath('report.Rmd')
# temporarily switch to the temp dir, in case you do not have write
# permission to the current working directory
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'report.Rmd', overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(varSite = input$pdfSite,
...
varTrans= input$valTrans1
)
# 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).
out <- render("report.Rmd", output_file = file,
params = params,
encoding = "UTF-8"
)
file.rename(out, file)
})
}
)
我认为我的应用程序未找到我的.Rmd文件,但如何解决?我所有的文件都在同一个文件夹中。
答案 0 :(得分:0)
我只运行了部分代码,显然问题出在您设置owd <- setwd(tempdir())
时
这是做什么的:
> tempdir()
[1] "/tmp/RtmpKafhlt"
> owd = setwd(tempdir())
> owd
[1] "/home/med"
,您可能无权访问主机服务器的主目录。您需要将on.exit(setwd(owd))
替换为on.exit(owd)