R/snapshot.R

Defines functions snapshot_slot snapshot_reactives

Documented in snapshot_reactives

#' @rdname reactives
#' @export
snapshot_reactives <- function(x) {

  check_collection(x)

  slots <- isolate(as.list(x))

  withReactiveDomain(
    NULL,
    build_reactives(lapply(slots, snapshot_slot), class(x))
  )
}

snapshot_slot <- function(slot) {

  if (inherits(slot, "reactiveVal")) {
    return(reactiveVal(isolate(slot())))
  }

  res <- tryCatch(
    list(value = isolate(slot())),
    error = function(e) list(error = e)
  )

  if (is.null(res$error)) {
    reactive(res$value)
  } else {
    reactive(stop(res$error))
  }
}

Try the reactives package in your browser

Any scripts or data that you put into this service are public.

reactives documentation built on Nov. 2, 2026, 9:06 a.m.