## ----setup, include=FALSE-----------------------------------------------------
library(teal)
library(ggplot2)
## ----static_decorator---------------------------------------------------------
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 +
ggtitle("This is a better title") +
xlab("the real x axis")
})
})
})
}
)
## ----interactive_decorator----------------------------------------------------
interactive_decorator <- teal_transform_module(
label = "Interactive decorator",
ui = function(id) {
ns <- NS(id)
div(
textInput(ns("x_axis_title"), "X axis title", value = "the suggested x axis")
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(),
{
plot <- plot +
ggtitle("This is a better title") +
xlab(my_title)
},
my_title = input$x_axis_title
)
})
})
}
)
## ----dynamic_decorator--------------------------------------------------------
dynamic_decorator <- function(output_name) {
teal_transform_module(
label = "Dynamic decorator",
ui = function(id) {
ns <- NS(id)
div(
textInput(ns("x_axis_title"), "X axis title", value = "the syggested x axis")
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(),
{
output_name <- output_name +
xlab(x_axis_title)
},
output_name = as.name(output_name),
x_axis_title = input$x_axis_title
)
})
})
}
)
}
## ----pseudo_module, eval = FALSE----------------------------------------------
# # styler: off
# pseudo_decorated_module <- function(
# label = "Pseudo Module with Decorator Support",
# decorators = list() # <--- added block (1)
# ) {
# module(
# label = label,
# ui_args = list(decorators = decorators), # <--- added block (2)
# server_args = list(decorators = decorators), # <--- added block (2)
# ui = function(id, decorators) {
# ns <- NS(id)
# div(
# # ,
# #