Set up auto-update/isolate logic for reactive contexts
Source:R/parse_utils.R
setup_auto_update_logic.RdA helper function that encapsulates the common pattern of handling auto-update functionality in module servers. When auto-update is disabled, it adds a dependency on the update button. Returns a wrapper function that either isolates reactive expressions or passes them through unchanged.
Value
A function that wraps reactive expressions. Returns identity if auto-update
is enabled (expressions will be reactive), or isolate if auto-update is disabled
(expressions will not trigger reactivity).
Details
This function consolidates the following common pattern:
auto_update <- input$auto.update
if (!auto_update) {
input$update
}
isolate_fn <- if (auto_update) identity else isolateUsage in a reactive context:
output$plot <- renderPlotly({
isolate_fn <- setup_auto_update_logic(input)
# Now use isolate_fn to wrap input values
x_val <- isolate_fn(input$x.value)
})Examples
if (FALSE) { # \dontrun{
# In a module server function:
output$myPlot <- renderPlot({
isolate_fn <- setup_auto_update_logic(input)
# Use isolate_fn to wrap inputs that should respect auto-update setting
ggplot(data(), aes(x = isolate_fn(input$x_var), y = isolate_fn(input$y_var))) +
geom_point()
})
} # }