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



An expression (quoted or unquoted).


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


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


A label for the observer, useful for debugging.


See domains.


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


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


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


# 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() # }