| teal_modules | R Documentation |
teal_module and teal_modules objectsCreate a nested tab structure to embed modules in a teal application.
module(
label = "module",
server = function(id, data, ...) moduleServer(id, function(input, output, session)
NULL),
ui = function(id, ...) tags$p(paste0("This module has no UI (id: ", id, " )")),
filters,
datanames = "all",
server_args = NULL,
ui_args = NULL,
transformators = list()
)
modules(..., label = character(0))
## S3 method for class 'teal_module'
format(
x,
is_last = FALSE,
parent_prefix = "",
what = c("datasets", "properties", "ui_args", "server_args", "decorators",
"transformators"),
...
)
## S3 method for class 'teal_modules'
format(x, is_root = TRUE, is_last = FALSE, parent_prefix = "", ...)
## S3 method for class 'teal_module'
print(x, ...)
## S3 method for class 'teal_modules'
print(x, ...)
label |
( |
server |
(
|
ui |
(
|
filters |
( |
datanames |
(
|
server_args |
(named |
ui_args |
(named |
transformators |
( |
... |
|
x |
( |
is_last |
( |
parent_prefix |
( |
what |
( |
is_root |
( |
module() creates an instance of a teal_module that can be placed in a teal application.
modules() shapes the structure of a the application by organizing teal_module within the navigation panel.
It wraps teal_module and teal_modules objects in a teal_modules object,
which results in a nested structure corresponding to the nested tabs in the final application.
Note that for modules() label comes after ..., so it must be passed as a named argument,
otherwise it will be captured by ....
The labels "global_filters" and "Report previewer" are reserved
because they are used by the mapping argument of teal_slices()
and the report previewer module reporter_previewer_module(), respectively.
module() returns an object of class teal_module.
modules() returns a teal_modules object which contains following fields:
label: taken from the label argument.
children: a list containing objects passed in .... List elements are named after
their label attribute converted to a valid shiny id.
teal_module:The datanames argument controls which datasets are used by the module's server. These datasets,
passed via server's data argument, are the only ones shown in the module's tab.
When datanames is set to "all", all datasets in the data object are treated as relevant.
However, this may include unnecessary datasets, such as:
Proxy variables for column modifications
Temporary datasets used to create final ones
Connection objects
Datasets which name is prefixed in teal_data by the dot (.) are not displayed in the teal application.
Please see the "Hidden datasets" section in 'vignette("including-data-in-teal-applications").
datanames with transformatorsWhen transformators are specified, their datanames are added to the module's datanames, which
changes the behavior as follows:
If module(datanames) is NULL and the transformators have defined datanames, the sidebar
will appear showing the transformators' datasets, instead of being hidden.
If module(datanames) is set to specific values and any transformator has datanames = "all",
the module may receive extra datasets that could be unnecessary
library(shiny)
module_1 <- module(
label = "a module",
server = function(id, data) {
moduleServer(
id,
module = function(input, output, session) {
output$data <- renderDataTable(data()[["iris"]])
}
)
},
ui = function(id) {
ns <- NS(id)
tagList(dataTableOutput(ns("data")))
},
datanames = "all"
)
module_2 <- module(
label = "another module",
server = function(id) {
moduleServer(
id,
module = function(input, output, session) {
output$text <- renderText("Another Module")
}
)
},
ui = function(id) {
ns <- NS(id)
tagList(textOutput(ns("text")))
},
datanames = NULL
)
modules <- modules(
label = "modules",
modules(
label = "nested modules",
module_1
),
module_2
)
app <- init(
data = teal_data(iris = iris),
modules = modules
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
mod <- module(
label = "My Custom Module",
server = function(id, data, ...) {},
ui = function(id, ...) {},
datanames = c("ADSL", "ADTTE"),
transformators = list(),
ui_args = list(a = 1, b = "b"),
server_args = list(x = 5, y = list(p = 1))
)
cat(format(mod))
custom_module <- function(
label = "label", ui_args = NULL, server_args = NULL,
datanames = "all", transformators = list(), bk = FALSE) {
ans <- module(
label,
server = function(id, data, ...) {},
ui = function(id, ...) {
},
datanames = datanames,
transformators = transformators,
ui_args = ui_args,
server_args = server_args
)
attr(ans, "teal_bookmarkable") <- bk
ans
}
dummy_transformator <- teal_transform_module(
label = "Dummy Transform",
ui = function(id) div("(does nothing)"),
server = function(id, data) {
moduleServer(id, function(input, output, session) data)
}
)
plot_transformator <- teal_transform_module(
label = "Plot Settings",
ui = function(id) div("(does nothing)"),
server = function(id, data) {
moduleServer(id, function(input, output, session) data)
}
)
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 title") +
xlab("x axis")
})
})
})
}
)
complete_modules <- modules(
custom_module(
label = "Data Overview",
datanames = c("ADSL", "ADAE", "ADVS"),
ui_args = list(
view_type = "table",
page_size = 10,
filters = c("ARM", "SEX", "RACE"),
decorators = list(static_decorator)
),
server_args = list(
cache = TRUE,
debounce = 1000,
decorators = list(static_decorator)
),
transformators = list(dummy_transformator),
bk = TRUE
),
modules(
label = "Nested 1",
custom_module(
label = "Interactive Plots",
datanames = c("ADSL", "ADVS"),
ui_args = list(
plot_type = c("scatter", "box", "line"),
height = 600,
width = 800,
color_scheme = "viridis"
),
server_args = list(
render_type = "svg",
cache_plots = TRUE
),
transformators = list(dummy_transformator, plot_transformator),
bk = TRUE
),
modules(
label = "Nested 2",
custom_module(
label = "Summary Statistics",
datanames = "ADSL",
ui_args = list(
stats = c("mean", "median", "sd", "range"),
grouping = c("ARM", "SEX")
)
),
modules(
label = "Labeled nested modules",
custom_module(
label = "Subgroup Analysis",
datanames = c("ADSL", "ADAE"),
ui_args = list(
subgroups = c("AGE", "SEX", "RACE"),
analysis_type = "stratified"
),
bk = TRUE
)
),
modules(custom_module(label = "Subgroup Analysis in non-labled modules"))
)
),
custom_module("Non-nested module")
)
cat(format(complete_modules))
cat(format(complete_modules, what = c("ui_args", "server_args", "transformators")))
cat(format(complete_modules, what = c("decorators", "transformators")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.