传递rmarkdown参数中的函数以在html报告中呈现绘图

传递rmarkdown参数中的函数以在html报告中呈现绘图,r,r-markdown,shiny,R,R Markdown,Shiny,我将从shiny生成的绘图传递到rmarkdown以生成html报告。问题是在rmarkdown文档的参数中接受wordcloud和饼图 问题:如何通过Shining在呈现的html中传递wordcloud和饼图 abc.Rmd title: "Report using R Markdown" subtitle: "ABC " author: "Author name" output: prettydoc::html_pretty: theme: architect para

我将从shiny生成的绘图传递到rmarkdown以生成html报告。问题是在rmarkdown文档的参数中接受wordcloud和饼图

问题:如何通过Shining在呈现的html中传递wordcloud和饼图

abc.Rmd

title: "Report using R Markdown"
subtitle: "ABC "
author: "Author name"
output:
     prettydoc::html_pretty:
     theme: architect
params:
    wc : 'NULL'
    table: 'NULL'
    pie: 'NULL'
title: "Report using R Markdown"
subtitle: "ABC "
author: "Author name"
output:
     prettydoc::html_pretty:
     theme: architect
params:
    wc : wc_function
    table: table_function
    pie: pie_function


 eval(paste0(param$wc_function, "(", my_options_as_string, ")")) 
app.R(片段)


注意:getWordcloud()、getTab()、getPie()函数在Shining应用程序中完全返回绘图。

您不能将函数作为参数类型

请参见此处的参数类型:

支持可由
yaml::yaml.load
函数解析的所有标准R类型,包括
字符
整数
数字
逻辑

我强烈建议您找到一种方法,使您的代码能够正常工作,而无需在参数中传递函数。也许您可以传递函数的选项并将函数包含在rmd中

但是,有办法绕过这一点:

一种是在参数中使用函数名作为字符串,并使用
eval()
作为代码计算字符串

abc.Rmd

title: "Report using R Markdown"
subtitle: "ABC "
author: "Author name"
output:
     prettydoc::html_pretty:
     theme: architect
params:
    wc : 'NULL'
    table: 'NULL'
    pie: 'NULL'
title: "Report using R Markdown"
subtitle: "ABC "
author: "Author name"
output:
     prettydoc::html_pretty:
     theme: architect
params:
    wc : wc_function
    table: table_function
    pie: pie_function


 eval(paste0(param$wc_function, "(", my_options_as_string, ")")) 
app.R(片段)

另一种方法是使用另一个r脚本和函数,在rmarkdown中使用
source
调用


这样,您就可以将文件的路径作为参数传递,并允许您访问rmarkdown中的函数(但这意味着函数的名称是固定的)

您的问题是什么?wc的值,即使我在应用程序的服务器端将绘图作为参数传递,饼图在rmarkdown中也显示为NULL。我的绘图是在shiny app的服务器端生成的,因此即使我从shinyoutput对象中获取文件读取对象,也不允许。是否要在rmarkdown中包括对shiny app的调用,如?实际上,反之亦然,我已经在我的闪亮应用程序中添加了下载按钮,该按钮将标记文档与我在闪亮应用程序中生成的绘图一起呈现为html文档为什么不直接在url中包含参数,如?通过这种方式,您可以在主页中包含一组按钮来定义参数,然后将链接重定向到生成的带有参数的rmarkdown。在rmarkdown中很容易包含js是可能的。这是一个很好的方法,但我一下载它为html,绘图就会显示在保存的html文件中。