metaRender {shinymeta} | R Documentation |
Create a meta-reactive output
Description
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 |
... |
Other arguments passed along to |
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 |
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 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.
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.
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)
}