我正在尝试构建一个带有闪亮R的webapp,它通过几个表,一个动态图和一个图像显示不同指标的值.结果就像是列表中所选项目的情况说明书,我想捕获结果并提供下载屏幕中显示的内容(表格,图形和图像)的可能性.
我看到我可以通过在Rmarkdown中生成报告并使用downloadHandler导出它,遵循此示例(http://dev.use-r.com/shiny-examples/016-knitr-pdf).据我所知,在服务器中输出$ downloadReport创建由文件名和内容组成的对象,该对象基于先前存储在与ui.R和server.R相同的目录中的报告的模板,具体如下:
#Output report
output$downloadReport <- downloadHandler(
filename = function() {
paste(input$City_id,'factsheet', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
))
},
content = function(file) {
src <- normalizePath('report.Rmd')
return(src)
# 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')
library(rmarkdown)
out <- render('report.Rmd', switch(
input$format,
PDF = pdf_document(), HTML = html_document(), Word = …Run Code Online (Sandbox Code Playgroud)