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

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.

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

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

See also

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