This function holds a block of code. The changes that the block makes do not become a step. They become part of the current state instead, so an undo never goes back across them. Use it for code that sets up a view: a saved view that you restore, a bookmark that you apply, or defaults that you load when the user logs in.
Usage
rewind_unrecorded(
expr,
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.- hold_ms
The time in milliseconds to keep the window open after the block. The default is two times the
coalesce_msof the session. Increase it if a slow browser lets a change through as a step.- session
The Shiny session. The default is the current session.
Details
It is the other side of rewind_step(). That function makes the changes
of a block into one step with a label. This one makes them into no step
at all.
Why not rewind_pause() and rewind_resume()
A pause and a resume in one observer have no effect. rewind captures
in its own observer, which runs after the one that made the change, so
capture has resumed by then. This function keeps a window open after
the block instead, so that the changes that come back from the browser
later are covered too.
What happens around it
A change from the user that still waits to be written becomes its own step first, so the block does not swallow it.
The steps in front of the position go, as they do for any change.
A change that the user makes inside the window is part of the current state too. Keep
hold_msshort.
Examples
if (interactive()) {
library(shiny)
server <- function(input, output, session) {
rewind_enable()
# A saved view. Loading it is not something to undo.
observeEvent(input$load_view, {
rewind_unrecorded({
updateSelectInput(session, "region", selected = "South")
updateSliderInput(session, "year", value = c(2020, 2024))
})
})
}
}
