0

I want to use data from my shiny app as params in Rmarkdown. How can I get my data and use it. Here is my app:

library(shiny)
library(readxl)
dat2 <-read_xlsx("data/iepp_18.xlsx")
shinyApp(    
    ui = fluidPage(
        selectInput("Ecole","Ecole", as.character(sort(unique(dat2$Nom_Ecole)))),
        downloadButton("report", "Generate report")
    ),
    server = function(input, output) {
        output$report <- downloadHandler(

            filename = "report.html",
            content = function(file) {

                tempReport <- file.path(tempdir(), "Reports.Rmd")
                file.copy("Reports.Rmd", tempReport, overwrite = TRUE)


                params <- list(base = input$Ecole)


                rmarkdown::render(tempReport, output_file = file,
                                  params = params,
                                  envir = new.env(parent = globalenv())
                )
            }
        )
    }
)

And here is my Rmd yaml

title: "Dynamic report"
output: html_document
params:
  base: NA

Is it not possible to subset the data in my Rmd with params$base?

``` r
 data_bulletin %>%
    filter(identification_nom_etablissement==params$base) 
```

Is it not possible to subset with params? Is it possible to use data from my shiny app in Rmarkdown?

Vishesh Shrivastav
  • 2,079
  • 2
  • 16
  • 34
Roland Samati
  • 77
  • 1
  • 5
  • 1
    What happens when you tried your code? Because we don't know what your data looks like, this question is unreproducible. At a minimum, I suggest you include the calling code (`rmarkdown::render`) any warnings or errors you get. Good refs for reproducibility: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Oct 14 '18 at 22:05
  • The subset with params don't work. – Roland Samati Oct 15 '18 at 06:26
  • 1
    That was obvious from the question, but *how it fails* is not apparent. For instance: (a) no data returned, no error, no warning; (b) all data incorrectly returned, no error, no warning; (c) no/wrong data returned, warning of `Warning: foo bar quux`; (d) failed with `Error: Result must have length 32, not 0`. You are less likely to get much help unless we have more context to help you. – r2evans Oct 15 '18 at 15:05

0 Answers0