I have the Shiny app below. The first time I select any given number it takes 3 seconds to load the result. Due to bindCache, I get the result instantly if I select the same number later.
However, I don't want to select all 10 numbers manually just to make my app responsive before I present it. Is there any way to cache a set of inputs in advance? In this example I'd want to cache the results for input$num values 1 through 10. In the real app there's approximately 5 inputs each with 5 possible values for 25 possible results I'd want to cache.
library(shiny)
ui <- fluidPage(
sliderInput('num', 'Pick a number:', min = 1, max = 10, value = 1),
textOutput('out')
)
server <- function(input, output, session) {
output$out <- reactive({
Sys.sleep(3)
paste("Your number is:", input$num)
}) %>% bindCache(input$num)
}
shinyApp(ui, server)
Note:
One response might be that I should manually pre-compute these results. In the real app most of the time comes from gt::render_gt and gt::gt_output on gt tables that I've created in advance. I believe these functions can only be used in a reactive context (meaning only in a Shiny app?)
Edit:
As a side-note, my original problem was solved by using gt::as_raw_html to render the tables in a step before the shiny app. Still leaving the question though, since it's sometimes a problem in other situations.