Captures the current input values and the registered server-side values
of the session into a snapshot object, ready for snap_write() or
snap_serialize(). Nothing is written to disk.
Usage
snap_take(
session = shiny::getDefaultReactiveDomain(),
...,
include = NULL,
exclude = NULL,
live_only = NULL,
values = TRUE,
scope = c("root", "module"),
meta = list()
)Arguments
- session
The Shiny session. Defaults to the current session.
- ...
Not used; arguments after
sessionmust be named.- include, exclude
Regular expressions matched against fully namespaced ids, in addition to those configured with
snap_enable().- live_only
Keep only inputs currently on the page. Defaults to the value configured with
snap_enable()(TRUE).- values
Capture tracked values and run the save hooks?
FALSEcaptures inputs only.- scope
"root"(the default) captures the whole app with full ids, even when called inside a module;"module"keeps only ids under the calling module's namespace (still as full ids).- meta
A named list of free-form metadata stored in the snapshot.
Details
What is captured:
Inputs, by fully namespaced id, exactly as
input$idreturns them. Withlive_only, only inputs that are currently on the page are kept, so values of inputs whose dynamic UI has been removed are not carried along. Action buttons, password inputs, and values that shiny's own serializers mark as unserializable are never captured; ids excluded withsetBookmarkExclude(),snap_exclude(), or theexcludepatterns are dropped. File inputs are moved to the snapshot'sattachments.The name of the client-side input binding of each captured input, in
bindings.Values: the fields of every
reactiveValuesregistered withsnap_track(), then whatever thesnap_on_save()hooks add.
The function isolates every read, so it never creates reactive dependencies. Inputs with a rate policy (text inputs debounce, sliders throttle) may lag the browser by a few hundred milliseconds; a snapshot taken from a download handler runs after the click has reached the server, which in practice is later than that.
Examples
if (interactive()) {
library(shiny)
server <- function(input, output, session) {
observeEvent(input$show, {
print(snap_take())
})
}
}
