snap_on_save() registers a function that snap_take() calls after the
inputs and tracked values have been collected. It receives a state
object: state$inputs is the named list of captured input values and
state$values is an environment. Anything the hook assigns into
state$values is stored in the snapshot's values section, so several
hooks (and several modules) can contribute without overwriting each other,
just like shiny's onBookmark().
Usage
snap_on_save(fn, session = shiny::getDefaultReactiveDomain())Details
Inside a module, the hook sees only the module's inputs (with the namespace prefix removed) and its values are stored under namespaced names automatically.
Examples
if (interactive()) {
library(shiny)
server <- function(input, output, session) {
snap_on_save(function(state) {
state$values$fitted_at <- format(Sys.time())
})
}
}
