[英]RShiny: How to pass variable from Server.R to an RMD script
我最近在玩RShiny,并且已经建立了一个工作的Web界面,该界面带有两个参数“ date”和“ location”,并从数据库中返回一系列符合条件的图形和表格。
我想要做的是让用户能够以HTML格式的RMD报告的形式下载所有数据和图形。
所以我有1.带下载按钮的UI.R 2. Server.R的downloadHandler启动了我的RMD脚本3。
UI.R
downloadButton('downloadData','Download')
Server.R
output$downloadData<- downloadHandler(filename ="myData.html",
content= function(file= NULL){
knit(thread.RMD)
}
这是我从Shiny Google网上论坛获得的答案: https : //groups.google.com/forum/? fromgroups =#!topic/ shiny-discuss/ XmW9V014EtI
作为downloadHandler的'content'参数提供的函数采用一个选项'file'。 单击下载按钮后,下载处理程序将调用该函数,并使用file参数告诉它应将输出文件保存在何处。
我看不到从knit2html()设置输出文件名的方法,但是您可以在创建它后重命名它:
output$downloadData <- downloadHandler(
filename ="ShinyData.html",
content = function(file) {
knit2html("myreport.rmd")
file.rename("myreport.html", file)
}
)
(此外,您在ui.r中缺少右括号。)
-Winston
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.