Input general data in a teal application
NEST CoreDev
2022-04-20
including-general-data-in-teal.Rmd
Introduction
Teal applications are not restricted to CDISC
-standard
data. Although many teal modules included with NEST
are
designed for CDISC
data, those in the library
teal.modules.general
have been designed to work with
non-relational data.
For example this application uses the standard iris
and
mtcars
datasets:
library(teal)
app <- init(
data = teal_data(
dataset("IRIS", iris, code = "IRIS <- iris"),
dataset("CARS", mtcars, code = "CARS <- mtcars")
),
modules = modules(example_module())
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
For more information, see documentation in
teal.data
.
Delayed Data Loading (DDL)
To learn more about DDL, visit
vignette("delayed-data-loading", package = "teal.data")
.
All the features of DDL are available for general datasets:
library(teal)
person_generator <- function() {
return(
data.frame(
ID = factor(1:8),
AGE = c(40, 23, 56, 11, 17, 71, 23, 56)
)
)
}
pet_generator <- function() {
return(
data.frame(
ID = factor(1:10),
TYPE = rep(c("CAT", "DOG"), 5),
COLOR = c("GINGER", rep("BROWN", 5), rep("BLACK", 4)),
PERSON_ID = factor(c(5, 4, 3, 3, 3, 1, 8, 1, 2, 2))
)
)
}
app <- init(
data = teal_data(
fun_dataset_connector("PERSON", fun = person_generator, keys = "ID") %>%
mutate_dataset("PERSON$SEX <- rep(c('M', 'F'), 4)"),
fun_dataset_connector("PETS", fun = pet_generator, keys = "ID")
) %>%
mutate_join_keys("PERSON", "PETS", c("ID" = "PERSON_ID")),
modules = modules(example_module())
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
For more information about preprocessing, reproducibility,
relationships between datasets and DDL, please refer to the teal.data
package.