R/data-static.R

Defines functions new_static_block

Documented in new_static_block

#' @section Static block:
#' Mainly useful for testing and examples, this block simply returns the data
#' with which it was initialized. Serialization of static blocks is not allowed
#' and exported code will not be self-contained in the sense that it will not
#' be possible to reproduce results in a script that contains code from a
#' static block.
#'
#' @param data Data (used directly as block result)
#'
#' @rdname new_data_block
#' @export
new_static_block <- function(data, ...) {

  ctor_envir <- environment()

  new_data_block(
    function(id) {
      moduleServer(
        id,
        function(input, output, session) {
          list(
            expr = reactive(
              bquote(get("data", envir = .(env)), list(env = ctor_envir))
            ),
            state = list(data = data)
          )
        }
      )
    },
    class = "static_block",
    ...
  )
}

#' @export
as.list.static_block <- function(x, ...) {
  stop("Cannot serialize upload blocks.")
}

Try the blockr.core package in your browser

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

blockr.core documentation built on June 8, 2025, 1:43 p.m.