# 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)
}
Run the code above in your browser using DataLab