Is it possible to make a Rmarkdown file reactive to a shiny app??

613 views
Skip to first unread message

Margarita Garfias

unread,
Apr 23, 2015, 1:33:18 PM4/23/15
to shiny-...@googlegroups.com
Hi!


I have a dynamic app (similar to this one ) in which I have some cities mapped out, and when the user clicks on a specific city, the app gives them information about it. All the info comes out of a data frame and everything works fine in the app. The thing is, I want the users to be able to download a PDF file specific to the city they clicked on. I have a .Rmd file prepared (as all the PDF's would have the same type of information, except it should be specific to the city, aka density, financial independece, etc.) but I can't find a way to link it to the shiny app, as in make the PDF display the name of the city and all of its specific information. I am able to download a "standard" PDF from the app--non reactive--, but I don't know if it is possible to make it reactive to the shiny app without having to make a specific file for each city?


The code I am using to download the pdf is this (and works fine):

output$downloadpdf <- downloadHandler(
    
    filename= "Report.pdf",
    
    content = function(file) {
      out = rmarkdown::render("Report.Rmd")
      file.rename(out, file)
    },
    
    contentType = 'application/pdf'
  )
  


And if I type this in my .Rmd to display the name of the chosen city (which is the same code I have in my server.R to display the name of the city):

```{r}
 
 ````
when I try downloading the PDF, it only renders this in a blank page: 
"Reading objects from shinyoutput object not allowed rmarkdown"


So, again, is there a way to  make my .Rmd (PDF) file reactive to my shiny app??


Thank you for your help!
Margarita

Joe Cheng

unread,
Apr 23, 2015, 5:43:22 PM4/23/15
to Margarita Garfias, shiny-...@googlegroups.com
Maybe try this:

    content = function(file) {
      inputEnv <- new.env()
      inputEnv$city <- input$city  # or whatever
      inputEnv$cityData <- cityData()
      out = rmarkdown::render("Report.Rmd", envir = inputEnv)
      file.rename(out, file)
    },

Then in your Rmd document you should be able to refer to city/cityData and get the values that you assigned to inputEnv.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/87cda326-d301-4b2c-a719-c71cec1e099b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages