2

I am passing plots generated from shiny to rmarkdown to generate html report. The trouble is wordcloud and pie chart are being accepted in params in rmarkdown document.

Question : How to pass wordcloud and pie plots in rendered html via shiny ?

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'

app.R(snippet)

rmarkdown::render(input = "report.Rmd",
                  output_file = "report.html",
                  params = list(wc=getWordcloud(),
                                table=getTab(),
                                pie=getPie()))

Note : getWordcloud(),getTab(),getPie() function are returning plots perfectly in shiny app.

2
  • 1
    What's your question? Commented Apr 28, 2017 at 10:17
  • values for wc,pie shows NULL in rmarkdown even when i pass plots as paramters in server side of my app Commented Apr 28, 2017 at 10:24

1 Answer 1

2

You can't have as a parameter type a function.

See here in parameter type: http://rmarkdown.rstudio.com/developer_parameterized_reports.html

All of the standard R types that can be parsed by the yaml::yaml.load function are supported including character, integer, numeric, and logical.

I strongly recommend to find a way to make your code working without the need to pass a function in the parameter. Maybe you can pass options of the function and include the function in the rmd?

But, there is ways to bypass that:

One is to use in the parameter the name of the function as a string and to use eval() to evaluate the string as code.

abc.Rmd

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(snippet)

rmarkdown::render(input = "report.Rmd",
                  output_file = "report.html",
                  params = list(wc="getWordcloud",
                                table="getTab",
                                pie="getPie"))

Another one is to have another r script with the functions, called in the rmarkdown with source.

That way, you can pass the path of the file as a parameter and it allows you to get access to your function inside the rmarkdown (but it implies the name of the functions are fixed)

Sign up to request clarification or add additional context in comments.

8 Comments

my plots are being generated in server side of shiny app, so even if i source my file Reading objects from shinyoutput object not allowed.
you want to include a call to a shiny app in your rmarkdown, like in that exemple?
actually it's vice versa, i have added download button in my shiny app which renders markdown document with my generated plots in shiny as html document
Why not directly include the parameters in the url, like here? That way, you can include a set of buttons in your main page to define your parameter then a redirect link to the generated rmarkdown with the parameters. It is possible to include js in your rmarkdown quite easily.
This is a good way but as soon as i download it as html, plots display in saved html file.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.