Create a meta-reactive output that, when invoked with meta-mode activated
(i.e. called within expandChain() or withMetaMode()), returns a
code expression (instead of evaluating that expression and returning the value).
Usage
metaRender(
renderFunc,
expr,
...,
env = parent.frame(),
quoted = FALSE,
localize = "auto",
bindToReturn = FALSE
)
metaRender2(renderFunc, expr, ..., env = parent.frame(), quoted = FALSE)Arguments
- renderFunc
A reactive output function (e.g., shiny::renderPlot, shiny::renderText, shiny::renderUI, etc).
- expr
An expression that generates given output expected by
renderFunc.- ...
Other arguments passed along to
renderFunc.- 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
xis a quosure andquotedisTRUE, thenenvis ignored.- quoted
If it is
TRUE, then thequote()ed value ofxwill be used whenxis evaluated. Ifxis a quosure and you would like to use its expression as a value forx, then you must setquotedtoTRUE.- localize
Whether or not to wrap the returned expression in
local(). The default,"auto", only wraps expressions with a top-levelreturn()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?
Value
An annotated render function, ready to be assigned to an output slot.
The function may also be called in meta mode (i.e., inside expandChain())
to return the code in quoted form.
Details
If you wish to capture specific code inside of expr (e.g. ignore code
that has no meaning outside shiny, like shiny::req()), use metaRender2() in combination
with metaExpr(). When using metaRender2(), expr must return a metaExpr().
Since package authors are allowed to create their own output rendering functions,
creating a meta-counterpart of an output renderer (e.g. renderPlot()) needs to be
more general than prefixing meta to the function name (as with metaReactive() and metaObserve()).
metaRender() makes some assumptions about the arguments taken by the render function,
assumptions that we believe are true for all existing render functions.
If you encounter a render function that doesn't seem to work properly,
please let us know by filing an issue on GitHub.
Examples
if (interactive()) {
library(shiny)
library(shinymeta)
ui <- fluidPage(
selectInput("var", label = "Choose a variable", choices = names(cars)),
verbatimTextOutput("Summary"),
verbatimTextOutput("code")
)
server <- function(input, output) {
var <- metaReactive({
cars[[..(input$var)]]
})
output$Summary <- metaRender(renderPrint, {
summary(..(var()))
})
output$code <- renderPrint({
expandChain(output$Summary())
})
}
shinyApp(ui, server)
}