R Shiny:如何将变量从Server.R传递给RMD脚本

时间:2013-04-09 16:34:15

标签: r scope knitr shiny

我最近正在和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) 
                                  }

1 个答案:

答案 0 :(得分:1)

  

以下是我从Shiny Google Group获得的答案: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

相关问题