metaReactive {shinymeta} | R Documentation |
Create a meta-reactive expression
Description
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).
Usage
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. If |
quoted |
If it is |
varname |
An R variable name that this object prefers to be named when
its code is extracted into an R script. (See also: |
domain |
See domains. |
inline |
If |
localize |
Whether or not to wrap the returned expression in |
bindToReturn |
For non- |
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 \{
.
Value
A function that, when called in meta mode (i.e. inside
expandChain()
), will return the code in quoted form. When called outside
meta mode, it acts the same as a regular shiny::reactive()
expression
call.
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())
expandChain(y())
y <- metaReactive2({
req(input$x)
metaExpr({
a <- ..(input$x) + 1
b <- a + 1
c + 1
}, bindToReturn = TRUE)
})
expandChain(y())