View source: R/tm_tbl_summary.R
| tm_tbl_summary | R Documentation |
teal module: GT Summary tableSummary table from a given dataset, using gtsummary.
tm_tbl_summary(
label = "Summary table",
by = NULL,
include = teal.picks::picks(teal.picks::datasets(), teal.picks::variables(selected =
dplyr::everything(), multiple = TRUE)),
dataname = NULL,
...,
col_label = NULL,
pre_output = NULL,
post_output = NULL,
transformators = list(),
decorators = list()
)
Object of class teal_module to be used in teal applications.
This module generates the following objects, which can be modified in place using decorators:
table (gtsummary - output of gtsummary::tbl_summary())
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_tbl_summary(
..., # arguments for module
decorators = list(
table = teal_transform_module(...) # applied to the `table` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.modules.general").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
The statistic argument specifies the statistics presented in the table. The
input dictates the summary statistics presented in the table. For example,
statistic = list(age ~ "{mean} ({sd})") would report the mean and
standard deviation for age; statistic = list(all_continuous() ~ "{mean} ({sd})")
would report the mean and standard deviation for all continuous variables.
The values are interpreted using glue::glue() syntax:
a name that appears between curly brackets will be interpreted as a function
name and the formatted result of that function will be placed in the table.
For categorical variables, the following statistics are available to display:
{n} (frequency), {N} (denominator), {p} (percent).
For continuous variables, any univariate function may be used.
The most commonly used functions are {median}, {mean}, {sd}, {min},
and {max}.
Additionally, {p##} is available for percentiles, where ## is an integer from 0 to 100.
For example, p25: quantile(probs=0.25, type=2).
When the summary type is "continuous2", pass a vector of statistics.
Each element of the vector will result in a separate row in the summary table.
For both categorical and continuous variables, statistics on the number of missing and non-missing observations and their proportions are available to display.
{N_obs} total number of observations
{N_miss} number of missing observations
{N_nonmiss} number of non-missing observations
{p_miss} percentage of observations missing
{p_nonmiss} percentage of observations not missing
The digits argument specifies the the number of digits (or formatting function) statistics are rounded to.
The values passed can either be a single integer, a vector of integers, a
function, or a list of functions. If a single integer or function is passed,
it is recycled to the length of the number of statistics presented.
For example, if the statistic is "{mean} ({sd})", it is equivalent to
pass 1, c(1, 1), label_style_number(digits=1), and
list(label_style_number(digits=1), label_style_number(digits=1)).
Named lists are also accepted to change the default formatting for a single
statistic, e.g. list(sd = label_style_number(digits=1)).
There are four summary types. Use the type argument to change the default summary types.
"continuous" summaries are shown on a single row. Most numeric
variables default to summary type continuous.
"continuous2" summaries are shown on 2 or more rows
"categorical" multi-line summaries of nominal data. Character variables,
factor variables, and numeric variables with fewer than 10 unique levels default to
type categorical. To change a numeric variable to continuous that
defaulted to categorical, use type = list(varname ~ "continuous")
"dichotomous" categorical variables that are displayed on a single row,
rather than one row per level of the variable.
Variables coded as TRUE/FALSE, 0/1, or yes/no are assumed to be dichotomous,
and the TRUE, 1, and yes rows are displayed.
Otherwise, the value to display must be specified in the value
argument, e.g. value = list(varname ~ "level to show")
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
# General example
data <- teal_data()
data <- within(data, CO2 <- CO2)
app <- init(
data = data,
modules = modules(
tm_tbl_summary(
by = teal.picks::picks(
datasets("CO2", "CO2"),
variables(selected = "Plant")
),
include = teal.picks::picks(
datasets("CO2", "CO2"),
variables(selected = c("Type", "Treatment"), multiple = TRUE)
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
data <- within(teal.data::teal_data(), {
ADSL <- teal.data::rADSL
ADTTE <- teal.data::rADTTE
})
join_keys(data) <- default_cdisc_join_keys[names(data)]
app <- init(
data = data,
modules = modules(
tm_tbl_summary(
by = teal.picks::picks(
datasets(c("ADSL", "ADTTE"), "ADTTE"),
variables(c("SEX", "COUNTRY", "SITEID", "ACTARM", "CNSR", "PARAMCD"), "SEX")
),
include = teal.picks::picks(
datasets(c("ADSL", "ADTTE"), "ADSL"),
variables(c("SITEID", "COUNTRY", "ACTARM", "SEX"), "SITEID", multiple = TRUE)
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.