Skip to contents

This function holds a block of code. Every change in that block becomes one history entry with the label that you give. Use it for buttons such as "reset all filters" or "apply preset". For these buttons, the standard time-based grouping can make several steps, or it can give a label that does not help the user.

Usage

rewind_step(
  expr,
  label = NULL,
  hold_ms = NULL,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

expr

The code to run. This is usually a set of update*Input() calls, or assignments to tracked reactive values.

label

The label for the history entry.

hold_ms

The time in milliseconds to keep the entry open. The default is two times the coalesce_ms of the session. Increase it if a slow browser makes two steps from one block.

session

The Shiny session. The default is the current session.

Value

The value of expr, invisibly.

Details

The block runs immediately. rewind writes the history entry after the changes return from the browser.

Examples

if (interactive()) {
  library(shiny)

  server <- function(input, output, session) {
    rewind_enable()

    observeEvent(input$reset, {
      rewind_step(label = "Reset filters", {
        updateSelectInput(session, "region", selected = "All")
        updateSliderInput(session, "year", value = c(2000, 2026))
        updateCheckboxInput(session, "only_active", value = FALSE)
      })
    })
  }
}