Create a reactive() that, when invoked with meta-mode activated (i.e. called within withMetaMode() or expandChain()), returns a code expression (instead of evaluating that expression and returning the value).

metaReactive(expr, env = parent.frame(), quoted = FALSE,
  varname = NULL, domain = shiny::getDefaultReactiveDomain(),
  inline = FALSE, localize = "auto", bindToReturn = FALSE)

metaReactive2(expr, env = parent.frame(), quoted = FALSE,
  varname = NULL, domain = shiny::getDefaultReactiveDomain(),
  inline = FALSE)

Arguments

expr

An expression (quoted or unquoted).

env

The parent environment for the reactive expression. By default, this is the calling environment, the same as when defining an ordinary non-reactive expression.

quoted

Is the expression quoted? By default, this is FALSE. This is useful when you want to use an expression that is stored in a variable; to do so, it must be quoted with quote().

varname

An R variable name that this object prefers to be named when its code is extracted into an R script. (See also: expandChain())

domain

See domains.

inline

If TRUE, during code expansion, do not declare a variable for this object; instead, inline the code into every call site. Use this to avoid introducing variables for very simple expressions. (See also: expandChain())

localize

Whether or not to wrap the returned expression in local(). The default, "auto", only wraps expressions with a top-level return() statement (i.e., return statements in anonymized functions are ignored).

bindToReturn

For non-localized expressions, should an assignment of a meta expression be applied to the last child of the top-level { call?

Details

If you wish to capture specific code inside of expr (e.g. ignore code that has no meaning outside shiny, like req()), use metaReactive2() in combination with metaExpr(). When using metaReactive2(), expr must return a metaExpr().

If varname is unspecified, srcrefs are used in attempt to infer the name bound to the meta-reactive object. In order for this inference to work, the keep.source option must be TRUE and expr must begin with {.

See also

Examples

library(shiny) options(shiny.suppressMissingContextError = TRUE) input <- list(x = 1) y <- metaReactive({ req(input$x) a <- ..(input$x) + 1 b <- a + 1 c + 1 }) withMetaMode(y())
#> req(input$x) #> a <- 1 + 1 #> b <- a + 1 #> c + 1
#> y <- { #> req(input$x) #> a <- 1 + 1 #> b <- a + 1 #> c + 1 #> } #> y
y <- metaReactive2({ req(input$x) metaExpr({ a <- ..(input$x) + 1 b <- a + 1 c + 1 }, bindToReturn = TRUE) }) expandChain(y())
#> a <- 1 + 1 #> b <- a + 1 #> y <- c + 1 #> y