I am working on a feature which allows my markdown file to conditionally execute chunks based on a parameters sent from my shiny app. Some information about how this works here: https://shiny.rstudio.com/articles/generating-reports.html
Within the downloadhandler()
there is an argument which calls upon params =
which I give it a list, for example that list would look like this;
params <- list(report_name = input$J, data = data(), data2 = data2())
So my aim is to have an if else statement that would code data2 to be NULL
or NA
with the following; data2 = if( exists("data2") ) {data2()} else {NA}
This would allow me to stop some chunks in markdown from running by setting the eval='someconditionthatsfalse'
if data2()
does not exists or is empty in some way.
The issue I am running into is that this always exists.
Any help would be greatly appreciated.
A reprex to help with the problem.
library(shiny)
ui <- fluidPage(
actionButton("simulate", "go"),
textOutput("doesitexist")
)
server <- function(input, output, session) {
output$doesitexist <- renderText({
if( exists("data2") ) {print("yes it exists")} else {print("not it does not exist")}
})
data2 <- eventReactive(input$simulate, {
data.frame(x = 1)
})
}
shinyApp(ui, server)