tm_t_crosstable {teal.modules.general} | R Documentation |
teal
module: Cross-table
Description
Generates a simple cross-table of two variables from a dataset with custom options for showing percentages and sub-totals.
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 |
( |
x |
( |
y |
(
|
show_percentage |
( |
show_total |
( |
pre_output |
( |
post_output |
( |
basic_table_args |
( For more details see the vignette: |
Value
Object of class teal_module
to be used in teal
applications.
Note
For more examples, please see the vignette "Using cross table" via
vignette("using-cross-table", package = "teal.modules.general")
.
Examples
# general data example
library(teal.widgets)
data <- teal_data()
data <- within(data, {
mtcars <- mtcars
for (v in c("cyl", "vs", "am", "gear")) {
mtcars[[v]] <- as.factor(mtcars[[v]])
}
mtcars[["primary_key"]] <- seq_len(nrow(mtcars))
})
datanames(data) <- "mtcars"
join_keys(data) <- join_keys(join_key("mtcars", "mtcars", "primary_key"))
app <- init(
data = data,
modules = modules(
tm_t_crosstable(
label = "Cross Table",
x = data_extract_spec(
dataname = "mtcars",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["mtcars"]], c("cyl", "vs", "am", "gear")),
selected = c("cyl", "gear"),
multiple = TRUE,
ordered = TRUE,
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "mtcars",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["mtcars"]], c("cyl", "vs", "am", "gear")),
selected = "vs",
multiple = FALSE,
fixed = FALSE
)
),
basic_table_args = basic_table_args(
subtitles = "Table generated by Crosstable Module"
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
library(teal.widgets)
data <- teal_data()
data <- within(data, {
ADSL <- rADSL
})
datanames(data) <- "ADSL"
join_keys(data) <- default_cdisc_join_keys[datanames(data)]
app <- init(
data = data,
modules = modules(
tm_t_crosstable(
label = "Cross Table",
x = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["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 = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], subset = function(data) {
idx <- vapply(data, is.factor, logical(1))
return(names(data)[idx])
}),
selected = "SEX",
multiple = FALSE,
fixed = FALSE
)
),
basic_table_args = basic_table_args(
subtitles = "Table generated by Crosstable Module"
)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}