2

I have configuration options for a shiny app that are behind a panel. Moreover, the configuration options are generated server side using uiOutput/renderUI. Shiny defers evaluation of items that are not in the currently selected panel, but sometimes it's desirable to force evaluation. Is it possible to force server side evaluation?

Here's an example:

library(shiny)

ui <- fluidPage(
    tabsetPanel(tabPanel("Main", 
                         plotOutput("dots")),
                tabPanel("Settings",
                         uiOutput("even.or.odd")
                )
    )   
)

server <- function(input, output) {

   output$dots <- renderPlot({
     plot(seq(ifelse(input$even, 0, 1), 20, 2))
   })
   output$even.or.odd <- renderUI(checkboxInput('even', "Even?",TRUE))
}

shinyApp(ui = ui, server = server)

Or from RStudio do runGist('https://gist.github.com/dkulp2/d897c21dfd1a20f9531b6454ea02a533')

This fails on startup because input$even is undefined until the "Settings" panel is revealed. (And then the app works fine.) Is there some way to cause Shiny to evaluate the even.or.odd function without revealing the panel?

Prradep
  • 5,506
  • 5
  • 43
  • 84
dk.
  • 2,030
  • 1
  • 22
  • 22
  • This example is trivial and a simple solution would be to remove the uiOutput/renderUI and just place the `checkboxInput` in the `ui`. But, in general assume that uiOutput/renderUI is required due to some server side logic. – dk. Oct 16 '17 at 03:22

1 Answers1

3

You can force execution of hidden output objects by setting suspendWhenHidden = FALSE with outputOptions

outputOptions(output, "even.or.odd", suspendWhenHidden = FALSE)
greg L
  • 4,034
  • 1
  • 19
  • 18
  • Where should the outputOptions dialog be placed? I suppose it has to be placed in the server (because that is where the `output` variable is available), but will that cause issues for [GUIs that take a long time to load?](https://stackoverflow.com/questions/48096603/shiny-start-the-app-with-hidden-tabs-with-no-delay) – Josiah Yoder Jun 28 '19 at 15:49
  • Yup, it should be placed in the server since it needs `output`. If rendering the hidden output requires long calculations on the server, then yes, it'll noticeably block the UI on load. – greg L Jun 28 '19 at 22:11