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"]])
}
)
}
Run the code above in your browser using DataLab