metaObserve | R Documentation |
Create a shiny::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()
)
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. If |
quoted |
If it is |
label |
A label for the observer, useful for debugging. |
domain |
See domains. |
localize |
Whether or not to wrap the returned expression in |
bindToReturn |
For non- |
If you wish to capture specific code inside of expr
(e.g. ignore
code that has no meaning outside shiny, like shiny::req()
), use
metaObserve2()
in combination with metaExpr()
. When using
metaObserve2()
, expr
must return a metaExpr()
.
A function that, when called in meta mode (i.e. inside
expandChain()
), will return the code in quoted form. If this function is
ever called outside of meta mode, it throws an error, as it is definitely
being called incorrectly.
metaExpr()
, ..
# observers execute 'immediately'
x <- 1
mo <- metaObserve({
x <<- x + 1
})
getFromNamespace("flushReact", "shiny")()
print(x)
# It only makes sense to invoke an meta-observer
# if we're in meta-mode (i.e., generating code)
expandChain(mo())
# Intentionally produces an error
## Not run: mo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.