createRenderFunction: Implement render functions

Description Usage Arguments Value See Also Examples

View source: R/shinywrappers.R

Description

This function is a wrapper for markRenderFunction() which provides support for async computation via promises.

Usage

1
2
3
4
5
6
7
8
9
createRenderFunction(
  func,
  transform = function(value, session, name, ...) value,
  outputFunc = NULL,
  outputArgs = NULL,
  cacheHint = "auto",
  cacheWriteHook = NULL,
  cacheReadHook = NULL
)

Arguments

func

A function without parameters, that returns user data. If the returned value is a promise, then the render function will proceed in async mode.

transform

A function that takes four arguments: value, session, name, and ... (for future-proofing). This function will be invoked each time a value is returned from func, and is responsible for changing the value into a JSON-ready value to be JSON-encoded and sent to the browser.

outputFunc

The UI function that is used (or most commonly used) with this render function. This can be used in R Markdown documents to create complete output widgets out of just the render function.

outputArgs

A list of arguments to pass to the uiFunc. Render functions should include outputArgs = list() in their own parameter list, and pass through the value to markRenderFunction, to allow app authors to customize outputs. (Currently, this is only supported for dynamically generated UIs, such as those created by Shiny code snippets embedded in R Markdown documents).

cacheHint

One of "auto", FALSE, or some other information to identify this instance for caching using bindCache(). If "auto", it will try to automatically infer caching information. If FALSE, do not allow caching for the object. Some render functions (such as renderPlot) contain internal state that makes them unsuitable for caching.

cacheWriteHook

Used if the render function is passed to bindCache(). This is an optional callback function to invoke before saving the value from the render function to the cache. This function must accept one argument, the value returned from renderFunc, and should return the value to store in the cache.

cacheReadHook

Used if the render function is passed to bindCache(). This is an optional callback function to invoke after reading a value from the cache (if there is a cache hit). The function will be passed one argument, the value retrieved from the cache. This can be useful when some side effect needs to occur for a render function to behave correctly. For example, some render functions call createWebDependency() so that Shiny is able to serve JS and CSS resources.

Value

An annotated render function, ready to be assigned to an output slot.

See Also

quoToFunction(), markRenderFunction().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# A very simple render function
renderTriple <- function(x) {
  x <- substitute(x)
  if (!rlang::is_quosure(x)) {
    x <- rlang::new_quosure(x, env = parent.frame())
  }
  func <- quoToFunction(x, "renderTriple")

  createRenderFunction(
    func,
    transform = function(value, session, name, ...) {
      paste(rep(value, 3), collapse=", ")
    },
    outputFunc = textOutput
  )
}

# Test render function from the console
a <- 1
r <- renderTriple({ a + 1 })
a <- 2
r()

shiny documentation built on Jan. 26, 2021, 1:06 a.m.