Create a observe()r that, when invoked with meta-mode activated (i.e. called within withMetaMode() or expandChain()), returns a partially evaluated code expression. Outside of meta-mode, metaObserve() is equivalent to observe() (it fully evaluates the given expression).

metaObserve(expr, env = parent.frame(), quoted = FALSE, label = NULL,
  domain = getDefaultReactiveDomain(), localize = "auto",
  bindToReturn = FALSE)

metaObserve2(expr, env = parent.frame(), quoted = FALSE,
  label = NULL, domain = getDefaultReactiveDomain())

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().

label

A label for the observer, useful for debugging.

domain

See domains.

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 metaObserve2() in combination with metaExpr(). When using metaObserve2(), expr must return a metaExpr().

See also

Examples

# observers execute 'immediately' x <- 1 mo <- metaObserve({ x <<- x + 1 }) shiny:::flushReact()
#> Top:
#> Bottom:
#> [1] 2
# It only makes sense to invoke an meta-observer # if we're in meta-mode (i.e., generating code) expandChain(mo())
#> x <<- x + 1
# Intentionally produces an error
# NOT RUN { mo() # }