Create a simple cross-table
tm_t_crosstable.RdCreate a simple cross-table
Usage
tm_t_crosstable(
label = "Cross Table",
x,
y,
show_percentage = TRUE,
show_total = TRUE,
pre_output = NULL,
post_output = NULL,
basic_table_args = teal.widgets::basic_table_args()
)Arguments
- label
(
character(1)) Label shown in the navigation item for the module. Any label possible except"global_filters"- read more inmappingargument of teal_slices.- x
(
data_extract_specorlistof multipledata_extract_spec) Object with all available choices with pre-selected option for variable X - row values. In case ofdata_extract_specuseselect_spec(..., ordered = TRUE)if table elements should be rendered according to selection order.- y
(
data_extract_specorlistof multipledata_extract_spec) Object with all available choices with pre-selected option for variable Y - column valuesdata_extract_specmust not allow multiple selection in this case.- show_percentage
optional, (
logical) Whether to show percentages (relevant only whenxis afactor). Defaults toTRUE.- show_total
optional, (
logical) Whether to show total column. Defaults toTRUE.- pre_output
(
shiny.tag, optional)
with text placed before the output to put the output into context. For example a title.- post_output
(
shiny.tag, optional) with text placed after the output to put the output into context. For example theshiny::helpText()elements are useful.- basic_table_args
-
(
basic_table_args) object created byteal.widgets::basic_table_args()with settings for the module table. The argument is merged with options variableteal.basic_table_argsand default module setup.For more details see the vignette:
vignette("custom-basic-table-arguments", package = "teal.widgets")
Note
For more examples, please see the vignette "Using cross table" via
vignette("using-cross-table", package = "teal.modules.general").
Examples
# Percentage cross table of variables from ADSL dataset
ADSL <- teal.modules.general::rADSL
app <- teal::init(
data = teal.data::cdisc_data(
teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- teal.modules.general::rADSL"),
check = TRUE
),
modules = teal::modules(
teal.modules.general::tm_t_crosstable(
label = "Cross Table",
x = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, subset = function(data) {
idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt"))
return(names(data)[idx])
}),
selected = "COUNTRY",
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
),
y = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
label = "Select variable:",
choices = variable_choices(ADSL, subset = function(data) {
idx <- vapply(data, is.factor, logical(1))
return(names(data)[idx])
}),
selected = "SEX",
multiple = FALSE,
fixed = FALSE
)
),
basic_table_args = teal.widgets::basic_table_args(
subtitles = "Table generated by Crosstable Module"
)
)
)
)
#> [INFO] 2023-08-14 13:51:40.1827 pid:1296 token:[] teal.modules.general Initializing tm_t_crosstable
if (interactive()) {
shinyApp(app$ui, app$server)
}