What is the best way to disable all inputs while the server is busy computing?
I have several inputs whose changes trigger small computations and the rendering of an output. Usually everything works fine, but if someone changes a slider or a numeric input too fast, the program gets stuck somewhere between data preparation/computation and plotting.
What is the best way to deal with such problems in 2023? Note that this is a very similar question to the one asked here.
Are there by now any solutions that work for a whole application with different modules without disabling/enabling each input with
shinyjs
? Also, for a dynamic UI, I am not a big fan of using an action button.
Here is an example, just try to increase the bins from 10 to 20.
histogramInput <- function(id) {
numericInput(NS(id, "bins"), "Select bins", 10, min = 1, step = 1)
}
histogramOutput <- function(id) {
plotOutput(NS(id, "histogram"))
}
histogramServer <- function(id, value) {
stopifnot(is.reactive(value))
moduleServer(id, function(input, output, session) {
# Some computational expensive data preparation
dat_hist <- reactive({
Sys.sleep(2)
print(input$bins)
list(dat = value(), bins = input$bins)
})
output$histogram <- renderPlot({
req(dat_hist())
graphics::hist(dat_hist()$dat, breaks = dat_hist()$bins)
}, res = 96)
})
}
histogramApp <- function() {
ui <- fluidPage(
histogramInput("test"),
histogramOutput("test")
)
server <- function(input, output, session) {
dat <- reactive({cars$speed})
histogramServer("test", dat)
}
shinyApp(ui, server)
}