# https://insightsengineering.github.io/teal/main/articles/getting-started-with-teal.html
# remember to change data and var name
# no clinical data
library (teal)
Warning: package 'teal' was built under R version 4.4.2
Loading required package: shiny
Loading required package: teal.data
Warning: package 'teal.data' was built under R version 4.4.2
Loading required package: teal.code
Warning: package 'teal.code' was built under R version 4.4.2
Loading required package: teal.slice
Warning: package 'teal.slice' was built under R version 4.4.2
Registered S3 method overwritten by 'teal':
method from
c.teal_slices teal.slice
You are using teal version 0.15.2
Attaching package: 'teal'
The following objects are masked from 'package:teal.slice':
as.teal_slices, teal_slices
library (teal.modules.clinical)
Warning: package 'teal.modules.clinical' was built under R version 4.4.2
Loading required package: teal.transform
Warning: package 'teal.transform' was built under R version 4.4.2
Loading required package: tern
Warning: package 'tern' was built under R version 4.4.2
Loading required package: rtables
Warning: package 'rtables' was built under R version 4.4.2
Loading required package: formatters
Warning: package 'formatters' was built under R version 4.4.2
Attaching package: 'formatters'
The following object is masked from 'package:base':
%||%
Loading required package: magrittr
Attaching package: 'rtables'
The following object is masked from 'package:utils':
str
Registered S3 method overwritten by 'tern':
method from
tidy.glm broom
library (teal.modules.general)
Warning: package 'teal.modules.general' was built under R version 4.4.2
Loading required package: ggmosaic
Warning: package 'ggmosaic' was built under R version 4.4.2
Loading required package: ggplot2
Warning: package 'ggpmisc' was built under R version 4.4.2
Loading required package: ggpp
Warning: package 'ggpp' was built under R version 4.4.2
Registered S3 methods overwritten by 'ggpp':
method from
heightDetails.titleGrob ggplot2
widthDetails.titleGrob ggplot2
Attaching package: 'ggpp'
The following object is masked from 'package:ggplot2':
annotate
library (ggpp)
library (goftest)
library (random.cdisc.data)
Warning: package 'random.cdisc.data' was built under R version 4.4.2
library (ggplot2)
library (sparkline)
Warning: package 'sparkline' was built under R version 4.4.2
Warning: package 'quarto' was built under R version 4.4.2
# 错误: 'rADLRS' is not an exported object from 'namespace:teal.modules.general'
# ADRS <- teal.modules.general::rADLRS
# ********************************************************************
# load data
# ********************************************************************
data <- teal_data ()
data <- within (data, {
ADSL <- teal.modules.general:: rADSL
ADTTE <- teal.modules.general:: rADTTE
ADLB <- teal.modules.general:: rADLB
ADRS <- random.cdisc.data:: cadrs %>%
dplyr:: filter (PARAMCD %in% c ("BESRSPI" , "INVET" ))
# Include `EOSDY` and `DCSREAS` variables below because they contain missing data.
stopifnot (
any (is.na (ADSL$ EOSDY)),
any (is.na (ADSL$ DCSREAS))
)
IRIS <- iris
MTCARS <- mtcars
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
ADSL <- df_explicit_na (ADSL)
ADTTE <- df_explicit_na (ADTTE)
ADLB <- df_explicit_na (ADLB)
ADRS <- df_explicit_na (ADRS)
})
datanames <- c ("ADSL" , "ADTTE" , "ADLB" , "ADRS" , "IRIS" , "MTCARS" )
datanames (data) <- datanames
join_keys (data) <- default_cdisc_join_keys[datanames]
# ********************************************************************
# for some modules: tte logistic module
# ********************************************************************
arm_ref_comp <- list (
ACTARMCD = list (
ref = "ARM B" ,
comp = c ("ARM A" , "ARM C" )
),
ARM = list (
ref = "B: Placebo" ,
comp = c ("A: Drug X" , "C: Combination" )
)
)
# ********************************************************************
# module: configuration for the two-datasets example
# ********************************************************************
data_table_mod <- tm_data_table (
label = "Data Review" ,
variables_selected = list (
ADSL = c ("STUDYID" , "USUBJID" , "SUBJID" , "SITEID" , "AGE" , "SEX" ),
ADTTE = c (
"STUDYID" , "USUBJID" , "SUBJID" , "SITEID" ,
"PARAM" , "PARAMCD" , "ARM" , "ARMCD" , "AVAL" , "CNSR"
)
)
)
[INFO] 2024-12-17 21:57:39.6967 pid:8300 token:[] teal.modules.general Initializing tm_data_table
# ********************************************************************
# summary_mod mean+freq for one var
# ********************************************************************
description_mod <- tm_t_summary (
label = "Description Table" ,
dataname = "ADSL" ,
arm_var = choices_selected (c ("ARM" , "ARMCD" ), "ARM" ),
summarize_vars = choices_selected (
c ("SEX" , "RACE" , "BMRKR2" , "EOSDY" , "DCSREAS" ),
c ("SEX" , "RACE" )
),
useNA = "ifany"
)
Initializing tm_t_summary
# ********************************************************************
# module: tm_outliers
# Initializing tm_t_summary_by
# 错误: 找不到对象'ADLB'
# data[["ADLB"]]
# choices = value_choices(ADLB, "PARAMCD", "PARAM"),
# choices = variable_choices(data[["ADLB"]], c("PARAM", "AVISIT")),
# ********************************************************************
description_by_var_mod <- tm_t_summary_by (
label = "BDS by Visit" ,
dataname = "ADLB" ,
arm_var = choices_selected (
choices = variable_choices (data[["ADSL" ]], c ("ARM" , "ARMCD" )),
selected = "ARM"
),
by_vars = choices_selected (
# note: order matters here. If `PARAM` is first, the split will be first by `PARAM` and then by `AVISIT`
choices = variable_choices (data[["ADLB" ]], c ("PARAM" , "AVISIT" )),
selected = c ("PARAM" , "AVISIT" )
),
summarize_vars = choices_selected (
choices = variable_choices (data[["ADLB" ]], c ("AVAL" )),
selected = c ("AVAL" )
),
useNA = "ifany" ,
paramcd = choices_selected (
choices = value_choices (data[["ADLB" ]], "PARAMCD" , "PARAM" ),
selected = "ALT"
)
)
Initializing tm_t_summary_by
# ********************************************************************
# module: tm_outliers
# ********************************************************************
# configuration for the single wide dataset
tm_outliers_mod1 <- tm_outliers (
label = "Outliers" ,
outlier_var = data_extract_spec (
dataname = "ADSL" ,
select = select_spec (
label = "Select variable:" ,
choices = variable_choices (data[["ADSL" ]], c ("AGE" , "BMRKR1" )),
selected = "AGE" ,
fixed = FALSE
)
),
categorical_var = data_extract_spec (
dataname = "ADSL" ,
select = select_spec (
label = "Select variables:" ,
choices = variable_choices (
data[["ADSL" ]],
subset = names (Filter (isTRUE, sapply (data[["ADSL" ]], is.factor)))
),
selected = "RACE" ,
multiple = FALSE ,
fixed = FALSE
)
)
)
[INFO] 2024-12-17 21:57:39.7840 pid:8300 token:[] teal.modules.general Initializing tm_outliers
# ********************************************************************
# module: tm_outliers
# ********************************************************************
tte_mod <- tm_t_tte (
label = "Time To Event Table" ,
dataname = "ADTTE" ,
arm_var = choices_selected (
variable_choices (data[["ADSL" ]], c ("ARM" , "ARMCD" , "ACTARMCD" )),
"ARM"
),
arm_ref_comp = arm_ref_comp,
paramcd = choices_selected (
value_choices (data[["ADTTE" ]], "PARAMCD" , "PARAM" ),
"OS"
),
strata_var = choices_selected (
variable_choices (data[["ADSL" ]], c ("SEX" , "BMRKR2" )),
"SEX"
),
time_points = choices_selected (c (6 , 8 ), 6 ),
event_desc_var = choices_selected (
variable_choices (data[["ADTTE" ]], "EVNTDESC" ),
"EVNTDESC" ,
fixed = TRUE
)
)
# ********************************************************************
# module: logstic_mod
# paramcd = choices_selected(
# choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"),
# selected = "ALT"
# )
# ********************************************************************
# ********************************************************************
# app
# update the data part
# PS: not ok, use teal_data() in data part
# ********************************************************************
app <- init (
data = data,
modules = modules (
data_table_mod,
tm_variable_browser (
label = "Variable Browser" ,
ggplot2_args = teal.widgets:: ggplot2_args (labs = list (subtitle = "Plot generated by Variable Browser Module" )),
),
tm_g_distribution (
label = "Distribution" ,
dist_var = teal.transform:: data_extract_spec (
dataname = "IRIS" ,
select = teal.transform:: select_spec (variable_choices ("IRIS" ), "Petal.Length" )
),
ggplot2_args = teal.widgets:: ggplot2_args (
labs = list (subtitle = "Plot generated by Distribution Module" )
)
),
tm_outliers_mod1,
description_mod,
description_by_var_mod,
tte_mod
),
filter = teal_slices (
teal_slice (dataname = "IRIS" , varname = "Species" , selected = "setosa" )
),
title = build_app_title (title = "My teal app" ),
header = h3 ("My teal application" ),
footer = tags$ div (a ("Powered by teal" , href = "https://insightsengineering.github.io/teal/latest-tag/" ))
)
[INFO] 2024-12-17 21:57:39.8189 pid:8300 token:[] teal.modules.general Initializing tm_variable_browser
[INFO] 2024-12-17 21:57:39.8285 pid:8300 token:[] teal.modules.general Initializing tm_g_distribution
# ********************************************************************
# run app
# ********************************************************************
if (interactive ()) {
shinyApp (app$ ui, app$ server, options = list (height = 1024 , width = 1024 ))
}