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

时间:2022-08-24 14:52:37

I am playing around with RShiny recently, and I've built a working web interface that takes two parameters "date" and "location" and gives me back a series of graphs and tables from our database that fit the criteria.

我最近正在玩RShiny,我已经构建了一个工作的Web界面,它接受两个参数“date”和“location”,并从我们的数据库中返回符合条件的一系列图形和表格。

What I would like to do with that, is to have users being able to download all the data and graphs in the form of a RMD report in HTML format.

我想做的是让用户能够以HTML格式下载RMD报告形式的所有数据和图形。

so I have 1. UI.R with a download button 2. Server.R's downloadHandler starts my RMD script 3. ????

所以我有1. UI.R下载按钮2. Server.R的downloadHandler启动我的RMD脚本3. ????

UI.R

UI.R

downloadButton('downloadData','Download')

Server.R

Server.R

output$downloadData<- downloadHandler(filename ="myData.html", 
                                  content= function(file= NULL){
                                    knit(thread.RMD) 
                                  }

1 个解决方案

#1


1  

Here is the answer I got from the Shiny Google Group : https://groups.google.com/forum/?fromgroups=#!topic/shiny-discuss/XmW9V014EtI

以下是我从Shiny Google Group获得的答案:https://groups.google.com/forum/?fromgroups =#!topic / shiny-discuss / XmW9V014EtI

The function that's given as the 'content' argument to downloadHandler takes one option, 'file'. When the download button is clicked, the download handler calls that function, and it uses the file argument to tell it where is should save the output file.

作为downloadHandler的'content'参数给出的函数采用一个选项'file'。单击下载按钮时,下载处理程序将调用该函数,并使用file参数告诉它应该保存输出文件的位置。

I don't see a way to set the output file name from knit2html(), but you can just rename it after it's created:

我没有看到从knit2html()设置输出文件名的方法,但您可以在创建后重命名它:

  output$downloadData <- downloadHandler(
    filename ="ShinyData.html", 
    content = function(file) {
      knit2html("myreport.rmd")
      file.rename("myreport.html", file)
    }
  )

(Also, you're missing a closing parenthesis in ui.r.)

(另外,你错过了ui.r中的右括号)

-Winston

-Winston

#1


1  

Here is the answer I got from the Shiny Google Group : https://groups.google.com/forum/?fromgroups=#!topic/shiny-discuss/XmW9V014EtI

以下是我从Shiny Google Group获得的答案:https://groups.google.com/forum/?fromgroups =#!topic / shiny-discuss / XmW9V014EtI

The function that's given as the 'content' argument to downloadHandler takes one option, 'file'. When the download button is clicked, the download handler calls that function, and it uses the file argument to tell it where is should save the output file.

作为downloadHandler的'content'参数给出的函数采用一个选项'file'。单击下载按钮时,下载处理程序将调用该函数,并使用file参数告诉它应该保存输出文件的位置。

I don't see a way to set the output file name from knit2html(), but you can just rename it after it's created:

我没有看到从knit2html()设置输出文件名的方法,但您可以在创建后重命名它:

  output$downloadData <- downloadHandler(
    filename ="ShinyData.html", 
    content = function(file) {
      knit2html("myreport.rmd")
      file.rename("myreport.html", file)
    }
  )

(Also, you're missing a closing parenthesis in ui.r.)

(另外,你错过了ui.r中的右括号)

-Winston

-Winston