Apply teal_transform_module decorators to reactive teal_data
Source: R/module_transform_data.R
module_transform_data.RdShiny module pair (srv_transform_teal_data / ui_transform_teal_data) that runs a sequence
of teal_transform_module() decorators against a reactive teal_data object.
Decorators are applied one after another via Reduce, so each one receives the output of the
previous as its data argument.
Failed transformators are tracked and any downstream transformator is automatically disabled
until the failure is resolved.
An optional expr argument allows additional code to be evaluated on the final decorated output.
Usage
srv_transform_teal_data(
id,
data,
transformators,
modules = NULL,
is_transform_failed = reactiveValues(),
expr
)
ui_transform_teal_data(id, transformators, class = "well", ...)Arguments
- id
(
character(1))shinymodule instance id.- data
(
teal_data,teal_data_module, orreactivereturningteal_data) The data which application will depend on.- transformators
(
listofteal_transform_module) decorator modules to apply sequentially todata. Each transformator receives the output of the previous one as input.- modules
- is_transform_failed
- expr
(
expressionorreactive) optional expression evaluated on top of the decorated output. Useful for post-processing after all transformators have run.- class
- ...
additional arguments passed to
.ui_transform_teal_data(e.g.class).
Value
reactive teal_data
A list of bslib::accordion UI elements, one per transformator, or NULL if
transformators is empty.
Examples
library(shiny)
library(teal.data)
# A decorator that sets a fixed title on a ggplot2 object named `plot`
static_decorator <- teal_transform_module(
label = "Static decorator",
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(), {
plot <- plot + ggplot2::ggtitle("Decorated title")
})
})
})
}
)
if (interactive()) {
shinyApp(
ui = fluidPage(
ui_transform_teal_data("decorate", transformators = list(static_decorator)),
plotOutput("plot")
),
server = function(input, output, session) {
data <- reactive(
teal_data(
plot = ggplot2::ggplot(iris, ggplot2::aes(Sepal.Length, Sepal.Width)) +
ggplot2::geom_point()
)
)
decorated <- srv_transform_teal_data(
"decorate",
data = data,
transformators = list(static_decorator)
)
output$plot <- renderPlot(decorated()[["plot"]])
}
)
}