| Title: | Longitudinal Visualization `teal` Modules |
|---|---|
| Description: | Modules that produce web interfaces through which longitudinal visualizations can be dynamically modified and displayed. These included box plot, correlation plot, density distribution plot, line plot, scatter plot and spaghetti plot with accompanying summary. Data are expected in ADaM structure. Requires analysis subject level (ADSL) and analysis laboratory (ADLB) data sets. Beyond core variables, Limit of Quantification flag variable (LOQFL) is expected with levels 'Y', 'N' or NA. |
| Authors: | Dony Unardi [aut, cre], Nick Paszty [aut], Dawid Kaledkowski [aut], Mahmoud Hallal [aut], Pawel Rucki [aut], Wenyi Liu [aut], Jeffrey Tomlinson [aut], Bali Toth [aut], Junlue Zhao [aut], Maciej Nasinski [aut], Maximilian Mordig [ctb], F. Hoffmann-La Roche AG [cph, fnd] |
| Maintainer: | Dony Unardi <[email protected]> |
| License: | Apache License 2.0 | file LICENSE |
| Version: | 0.6.1.9000 |
| Built: | 2026-10-14 22:50:45 UTC |
| Source: | https://github.com/insightsengineering/teal.goshawk |
Provides lines of code for left hand side of arm mapping. user must provide right hand side
maptrt(df_armvar, code = c("M", "O"))maptrt(df_armvar, code = c("M", "O"))
df_armvar |
the dataframe and column name containing treatment code. e.g. |
code |
controls whether mapping or ordering code is written to console. Valid values: |
SPA configure study specific pre-processing for deploying goshawk. writing the code for ARM mapping and
ordering is tedious. this function helps to get that started by providing the left hand side of the
mapping and ordering syntax. call the function and then copy and paste the resulting code from the console
into the app.R file.
Data frame with the unique treatment codes. The function prints the left hand side of the mapping or ordering code to the console.
ADSL <- teal.data::rADSL # get treatment mapping code maptrt(df_armvar = ADSL$ARMCD, code = "M") # get treatment ordering code maptrt(df_armvar = ADSL$ARMCD, code = "O")ADSL <- teal.data::rADSL # get treatment mapping code maptrt(df_armvar = ADSL$ARMCD, code = "M") # get treatment ordering code maptrt(df_armvar = ADSL$ARMCD, code = "O")
This teal module renders the UI and calls the functions that create a box plot and accompanying summary table.
tm_g_gh_boxplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), yaxis_var = teal.picks::variables(c("AVAL", "CHG"), "AVAL"), xaxis_var = teal.picks::variables("AVISITCD", "AVISITCD"), facet_var = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), trt_group = teal.picks::variables(selected = "ARM"), color_manual = NULL, shape_manual = NULL, facet_ncol = NULL, loq_legend = TRUE, rotate_xlab = FALSE, hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", hline_vars = character(0), hline_vars_colors = "green", hline_vars_labels = hline_vars, plot_height = c(600, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), dot_size = c(2, 1, 12), alpha = c(0.8, 0, 1), pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )tm_g_gh_boxplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), yaxis_var = teal.picks::variables(c("AVAL", "CHG"), "AVAL"), xaxis_var = teal.picks::variables("AVISITCD", "AVISITCD"), facet_var = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), trt_group = teal.picks::variables(selected = "ARM"), color_manual = NULL, shape_manual = NULL, facet_ncol = NULL, loq_legend = TRUE, rotate_xlab = FALSE, hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", hline_vars = character(0), hline_vars_colors = "green", hline_vars_labels = hline_vars, plot_height = c(600, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), dot_size = c(2, 1, 12), alpha = c(0.8, 0, 1), pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )
label |
( |
dataname |
( |
param_var |
|
param |
( |
yaxis_var |
( |
xaxis_var |
( |
facet_var |
( |
trt_group |
( |
color_manual |
(named |
shape_manual |
(named |
facet_ncol |
( |
loq_legend |
( |
rotate_xlab |
( |
hline_arb |
( |
hline_arb_color |
( |
hline_arb_label |
( |
hline_vars |
( |
hline_vars_colors |
( |
hline_vars_labels |
( |
plot_height |
( |
plot_width |
( |
font_size |
( |
dot_size |
( |
alpha |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
See section "Decorating Module" below for more details. |
A teal::module() object that can be used in a teal::init() call.
This module generates the following objects, which can be modified in place using decorators:
plot (ggplot)
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_g_gh_boxplot(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied only to `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.goshawk").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Jeff Tomlinson
Balazs Toth
# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(nestcolor) library(stringr) # use non-exported function from goshawk .h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD), ANRLO = 50, ANRHI = 75 ) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables ALB_LOQS <- .h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_boxplot( label = "Box Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), yaxis_var = variables(c("AVAL", "BASE", "CHG"), "AVAL"), xaxis_var = variables(c("ACTARM", "ARM", "AVISITCD", "STUDYID"), "ARM"), facet_var = variables(c("ACTARM", "ARM", "AVISITCD", "SEX"), "AVISITCD"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), loq_legend = TRUE, rotate_xlab = FALSE, hline_arb = c(60, 55), hline_arb_color = c("grey", "red"), hline_arb_label = c("default_hori_A", "default_hori_B"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("pink", "brown", "purple", "black") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(nestcolor) library(stringr) # use non-exported function from goshawk .h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD), ANRLO = 50, ANRHI = 75 ) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables ALB_LOQS <- .h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_boxplot( label = "Box Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), yaxis_var = variables(c("AVAL", "BASE", "CHG"), "AVAL"), xaxis_var = variables(c("ACTARM", "ARM", "AVISITCD", "STUDYID"), "ARM"), facet_var = variables(c("ACTARM", "ARM", "AVISITCD", "SEX"), "AVISITCD"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), loq_legend = TRUE, rotate_xlab = FALSE, hline_arb = c(60, 55), hline_arb_color = c("grey", "red"), hline_arb_label = c("default_hori_A", "default_hori_B"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("pink", "brown", "purple", "black") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }
Scatter Plot Teal Module For Biomarker Analysis
tm_g_gh_correlationplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), xaxis_param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), xaxis_var = teal.picks::variables(c("AVAL", "BASE", "CHG", "PCHG"), "BASE"), yaxis_param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "CRP", multiple = FALSE), check_dataset = FALSE), yaxis_var = teal.picks::variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), color_manual = NULL, shape_manual = NULL, facet_ncol = 2, visit_facet = TRUE, trt_facet = FALSE, reg_line = FALSE, loq_legend = TRUE, rotate_xlab = FALSE, hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", hline_vars = character(0), hline_vars_colors = "green", hline_vars_labels = hline_vars, vline_arb = numeric(0), vline_arb_color = "red", vline_arb_label = "Vertical line", vline_vars = character(0), vline_vars_colors = "green", vline_vars_labels = vline_vars, plot_height = c(500, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), dot_size = c(1, 1, 12), reg_text_size = c(3, 3, 10), pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )tm_g_gh_correlationplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), xaxis_param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), xaxis_var = teal.picks::variables(c("AVAL", "BASE", "CHG", "PCHG"), "BASE"), yaxis_param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "CRP", multiple = FALSE), check_dataset = FALSE), yaxis_var = teal.picks::variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), color_manual = NULL, shape_manual = NULL, facet_ncol = 2, visit_facet = TRUE, trt_facet = FALSE, reg_line = FALSE, loq_legend = TRUE, rotate_xlab = FALSE, hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", hline_vars = character(0), hline_vars_colors = "green", hline_vars_labels = hline_vars, vline_arb = numeric(0), vline_arb_color = "red", vline_arb_label = "Vertical line", vline_vars = character(0), vline_vars_colors = "green", vline_vars_labels = vline_vars, plot_height = c(500, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), dot_size = c(1, 1, 12), reg_text_size = c(3, 3, 10), pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )
label |
( |
dataname |
( |
param_var |
|
xaxis_param |
( |
xaxis_var |
( |
yaxis_param |
( |
yaxis_var |
( |
trt_group |
( |
color_manual |
(named |
shape_manual |
(named |
facet_ncol |
( |
visit_facet |
( |
trt_facet |
( |
reg_line |
( |
loq_legend |
( |
rotate_xlab |
( |
hline_arb |
( |
hline_arb_color |
( |
hline_arb_label |
( |
hline_vars |
( |
hline_vars_colors |
( |
hline_vars_labels |
( |
vline_arb |
( |
vline_arb_color |
( |
vline_arb_label |
( |
vline_vars |
( |
vline_vars_colors |
( |
vline_vars_labels |
( |
plot_height |
( |
plot_width |
( |
font_size |
( |
dot_size |
( |
reg_text_size |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
See section "Decorating Module" below for more details. |
A teal::module() object that can be used in a teal::init() call.
This module generates the following objects, which can be modified in place using decorators:
plot (ggplot)
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_g_gh_correlationplot(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied only to `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.goshawk").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Nick Paszty
Balazs Toth
# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # use non-exported function from goshawk .h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) .color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") # assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA" .shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate(AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste( "W", trimws( substr( AVISIT, start = 6, stop = str_locate(AVISIT, "DAY") - 1 ) ) ), TRUE ~ NA_character_ )) %>% mutate(AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ NA_real_ )) %>% # use ARMCD values to order treatment in visualization legend mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, ifelse(grepl("B", ARMCD), 2, ifelse(grepl("A", ARMCD), 3, NA) ) )) %>% mutate(ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))])) %>% mutate(ARM = factor(ARM) %>% reorder(TRTORD)) %>% mutate( ANRHI = case_when( PARAMCD == "ALT" ~ 60, PARAMCD == "CRP" ~ 70, PARAMCD == "IGA" ~ 80, TRUE ~ NA_real_ ), ANRLO = case_when( PARAMCD == "ALT" ~ 20, PARAMCD == "CRP" ~ 30, PARAMCD == "IGA" ~ 40, TRUE ~ NA_real_ ) ) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" # add LLOQ and ULOQ variables ADLB_LOQS <- .h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM") }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_correlationplot( label = "Correlation Plot", dataname = "ADLB", xaxis_param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), yaxis_param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "CRP", multiple = FALSE), check_dataset = FALSE ), xaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "BASE"), yaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), color_manual = c( "Drug X 100mg" = "#000000", "Placebo" = "#3498DB", "Combination 100mg" = "#E74C3C" ), shape_manual = c("N" = 1, "Y" = 2, "NA" = 0), plot_height = c(500, 200, 2000), facet_ncol = 2, visit_facet = TRUE, reg_line = FALSE, loq_legend = TRUE, font_size = c(12, 8, 20), dot_size = c(1, 1, 12), reg_text_size = c(3, 3, 10), hline_arb = c(40, 50), hline_arb_label = "arb hori label", hline_arb_color = c("red", "blue"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("green", "blue", "purple", "cyan"), hline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), vline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), vline_vars_colors = c("yellow", "orange", "brown", "gold"), vline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), vline_arb = c(50, 70), vline_arb_label = "arb vert A", vline_arb_color = c("green", "orange") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # use non-exported function from goshawk .h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) .color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") # assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA" .shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate(AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste( "W", trimws( substr( AVISIT, start = 6, stop = str_locate(AVISIT, "DAY") - 1 ) ) ), TRUE ~ NA_character_ )) %>% mutate(AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ NA_real_ )) %>% # use ARMCD values to order treatment in visualization legend mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, ifelse(grepl("B", ARMCD), 2, ifelse(grepl("A", ARMCD), 3, NA) ) )) %>% mutate(ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))])) %>% mutate(ARM = factor(ARM) %>% reorder(TRTORD)) %>% mutate( ANRHI = case_when( PARAMCD == "ALT" ~ 60, PARAMCD == "CRP" ~ 70, PARAMCD == "IGA" ~ 80, TRUE ~ NA_real_ ), ANRLO = case_when( PARAMCD == "ALT" ~ 20, PARAMCD == "CRP" ~ 30, PARAMCD == "IGA" ~ 40, TRUE ~ NA_real_ ) ) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse( USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" # add LLOQ and ULOQ variables ADLB_LOQS <- .h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM") }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_correlationplot( label = "Correlation Plot", dataname = "ADLB", xaxis_param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), yaxis_param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "CRP", multiple = FALSE), check_dataset = FALSE ), xaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "BASE"), yaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), color_manual = c( "Drug X 100mg" = "#000000", "Placebo" = "#3498DB", "Combination 100mg" = "#E74C3C" ), shape_manual = c("N" = 1, "Y" = 2, "NA" = 0), plot_height = c(500, 200, 2000), facet_ncol = 2, visit_facet = TRUE, reg_line = FALSE, loq_legend = TRUE, font_size = c(12, 8, 20), dot_size = c(1, 1, 12), reg_text_size = c(3, 3, 10), hline_arb = c(40, 50), hline_arb_label = "arb hori label", hline_arb_color = c("red", "blue"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("green", "blue", "purple", "cyan"), hline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), vline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), vline_vars_colors = c("yellow", "orange", "brown", "gold"), vline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), vline_arb = c(50, 70), vline_arb_label = "arb vert A", vline_arb_color = c("green", "orange") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }
This teal module renders the UI and calls the functions that create a density distribution plot and an accompanying summary table.
tm_g_gh_density_distribution_plot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), xaxis_var = teal.picks::variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), color_manual = NULL, color_comb = NULL, plot_height = c(500, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), line_size = c(1, 0.25, 3), hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", facet_ncol = 2L, comb_line = TRUE, rotate_xlab = FALSE, pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )tm_g_gh_density_distribution_plot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), xaxis_var = teal.picks::variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), color_manual = NULL, color_comb = NULL, plot_height = c(500, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), line_size = c(1, 0.25, 3), hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", facet_ncol = 2L, comb_line = TRUE, rotate_xlab = FALSE, pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )
label |
( |
dataname |
( |
param_var |
|
param |
( |
xaxis_var |
( |
trt_group |
( |
color_manual |
(named |
color_comb |
name or hex value for combined treatment color. |
plot_height |
( |
plot_width |
( |
font_size |
( |
line_size |
plot line thickness. |
hline_arb |
( |
hline_arb_color |
( |
hline_arb_label |
( |
facet_ncol |
( |
comb_line |
display combined treatment line toggle. |
rotate_xlab |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
See section "Decorating Module" below for more details. |
A teal::module() object that can be used in a teal::init() call.
This module generates the following objects, which can be modified in place using decorators:
plot (ggplot)
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_g_gh_density_distribution_plot(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied only to `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.goshawk").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Nick Paszty
Balazs Toth
# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD) ) attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_density_distribution_plot( label = "Density Distribution Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), xaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), color_manual = c( "150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C" ), color_comb = "#39ff14", comb_line = TRUE, plot_height = c(500, 200, 2000), font_size = c(12, 8, 20), line_size = c(1, .25, 3), hline_arb = c(.02, .05), hline_arb_color = c("red", "black"), hline_arb_label = c("Horizontal Line A", "Horizontal Line B") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD) ) attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_density_distribution_plot( label = "Density Distribution Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), xaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), color_manual = c( "150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C" ), color_comb = "#39ff14", comb_line = TRUE, plot_height = c(500, 200, 2000), font_size = c(12, 8, 20), line_size = c(1, .25, 3), hline_arb = c(.02, .05), hline_arb_color = c("red", "black"), hline_arb_label = c("Horizontal Line A", "Horizontal Line B") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }
This teal module renders the UI and calls the function that creates a line plot.
tm_g_gh_lineplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), param_var_label = "PARAM", xaxis_var = teal.picks::variables(dplyr::starts_with("AVISIT"), "AVISITCD"), yaxis_var = teal.picks::variables(c("AVAL", "CHG", "PCHG"), "AVAL"), xvar_level = NULL, filter_var = lifecycle::deprecated(), filter_var_choices = lifecycle::deprecated(), trt_group = teal.picks::variables(selected = "ARM"), trt_group_level = NULL, shape_choices = NULL, stat = "mean", hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", color_manual = c(getOption("ggplot2.discrete.colour"), c("#ff0000", "#008000", "#4ca3dd", "#8a2be2"))[1:4], xtick = ggplot2::waiver(), xlabel = xtick, rotate_xlab = FALSE, plot_height = c(600, 200, 4000), plot_width = NULL, plot_font_size = c(12, 8, 20), dodge = c(0.4, 0, 1), pre_output = NULL, post_output = NULL, count_threshold = 0, table_font_size = c(12, 4, 20), dot_size = c(2, 1, 12), plot_relative_height_value = 1000, transformators = list(), decorators = list() )tm_g_gh_lineplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), param_var_label = "PARAM", xaxis_var = teal.picks::variables(dplyr::starts_with("AVISIT"), "AVISITCD"), yaxis_var = teal.picks::variables(c("AVAL", "CHG", "PCHG"), "AVAL"), xvar_level = NULL, filter_var = lifecycle::deprecated(), filter_var_choices = lifecycle::deprecated(), trt_group = teal.picks::variables(selected = "ARM"), trt_group_level = NULL, shape_choices = NULL, stat = "mean", hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", color_manual = c(getOption("ggplot2.discrete.colour"), c("#ff0000", "#008000", "#4ca3dd", "#8a2be2"))[1:4], xtick = ggplot2::waiver(), xlabel = xtick, rotate_xlab = FALSE, plot_height = c(600, 200, 4000), plot_width = NULL, plot_font_size = c(12, 8, 20), dodge = c(0.4, 0, 1), pre_output = NULL, post_output = NULL, count_threshold = 0, table_font_size = c(12, 4, 20), dot_size = c(2, 1, 12), plot_relative_height_value = 1000, transformators = list(), decorators = list() )
label |
( |
dataname |
( |
param_var |
|
param |
( |
param_var_label |
( |
xaxis_var |
( |
yaxis_var |
( |
xvar_level |
( |
filter_var |
|
filter_var_choices |
|
trt_group |
( |
trt_group_level |
( |
shape_choices |
( |
stat |
( |
hline_arb |
( |
hline_arb_color |
( |
hline_arb_label |
( |
color_manual |
(named |
xtick |
( |
xlabel |
( |
rotate_xlab |
( |
plot_height |
( |
plot_width |
( |
plot_font_size |
( |
dodge |
( |
pre_output |
( |
post_output |
( |
count_threshold |
( |
table_font_size |
( |
dot_size |
( |
plot_relative_height_value |
( |
transformators |
( |
decorators |
See section "Decorating Module" below for more details. |
A teal::module() object that can be used in a teal::init() call.
This module generates the following objects, which can be modified in place using decorators:
plot (ggplot)
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_g_gh_lineplot(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied only to `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.goshawk").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Wenyi Liu
Balazs Toth
# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) library(nestcolor) # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD) ) attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_lineplot( label = "Line Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), shape_choices = c("SEX", "RACE"), xaxis_var = variables("AVISITCD", "AVISITCD"), yaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), hline_arb = c(20.5, 19.5), hline_arb_color = c("red", "green"), hline_arb_label = c("A", "B") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) library(nestcolor) # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD) ) attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_lineplot( label = "Line Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), shape_choices = c("SEX", "RACE"), xaxis_var = variables("AVISITCD", "AVISITCD"), yaxis_var = variables(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), hline_arb = c(20.5, 19.5), hline_arb_color = c("red", "green"), hline_arb_label = c("A", "B") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }
This teal module renders the UI and calls the function that creates a spaghetti plot.
tm_g_gh_spaghettiplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), param_var_label = "PARAM", idvar = "USUBJID", xaxis_var = teal.picks::variables(c("AVISITCD", "AVISIT"), "AVISITCD"), yaxis_var = teal.picks::variables(c("AVAL", "CHG", "PCHG"), "AVAL"), xaxis_var_level = NULL, filter_var = lifecycle::deprecated(), trt_group = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), trt_group_level = NULL, group_stats = "NONE", man_color = NULL, color_comb = NULL, xtick = ggplot2::waiver(), xlabel = xtick, rotate_xlab = FALSE, facet_ncol = 2, free_x = FALSE, plot_height = c(600, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), dot_size = c(2, 1, 12), hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", hline_vars = character(0), hline_vars_colors = "green", hline_vars_labels = hline_vars, alpha = c(0.8, 0, 1), pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )tm_g_gh_spaghettiplot( label, dataname = "ADLB", param_var = lifecycle::deprecated(), param = teal.picks::picks(teal.picks::variables("PARAMCD", "PARAMCD"), teal.picks::values(selected = "ALT", multiple = FALSE), check_dataset = FALSE), param_var_label = "PARAM", idvar = "USUBJID", xaxis_var = teal.picks::variables(c("AVISITCD", "AVISIT"), "AVISITCD"), yaxis_var = teal.picks::variables(c("AVAL", "CHG", "PCHG"), "AVAL"), xaxis_var_level = NULL, filter_var = lifecycle::deprecated(), trt_group = teal.picks::variables(dplyr::starts_with("ARM"), selected = "ARM"), trt_group_level = NULL, group_stats = "NONE", man_color = NULL, color_comb = NULL, xtick = ggplot2::waiver(), xlabel = xtick, rotate_xlab = FALSE, facet_ncol = 2, free_x = FALSE, plot_height = c(600, 200, 2000), plot_width = NULL, font_size = c(12, 8, 20), dot_size = c(2, 1, 12), hline_arb = numeric(0), hline_arb_color = "red", hline_arb_label = "Horizontal line", hline_vars = character(0), hline_vars_colors = "green", hline_vars_labels = hline_vars, alpha = c(0.8, 0, 1), pre_output = NULL, post_output = NULL, transformators = list(), decorators = list() )
label |
menu item label of the module in the teal app. |
dataname |
analysis data passed to the data argument of |
param_var |
|
param |
( |
param_var_label |
( |
idvar |
name of unique subject id variable. |
xaxis_var |
( |
yaxis_var |
( |
xaxis_var_level |
vector that can be used to define the factor level of |
filter_var |
|
trt_group |
( |
trt_group_level |
( |
group_stats |
control group mean or median overlay. |
man_color |
string vector representing customized colors |
color_comb |
name or hex value for combined treatment color. |
xtick |
( |
xlabel |
( |
rotate_xlab |
( |
facet_ncol |
( |
free_x |
|
plot_height |
( |
plot_width |
( |
font_size |
( |
dot_size |
( |
hline_arb |
( |
hline_arb_color |
( |
hline_arb_label |
( |
hline_vars |
( |
hline_vars_colors |
( |
hline_vars_labels |
( |
alpha |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
See section "Decorating Module" below for more details. |
A teal::module() object that can be used in a teal::init() call.
This module generates the following objects, which can be modified in place using decorators:
plot (ggplot)
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_g_gh_spaghettiplot(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied only to `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.goshawk").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")
vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Wenyi Liu
Balazs Toth
# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # use non-exported function from goshawk .h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD), ANRLO = 30, ANRHI = 75 ) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables ALB_LOQS <- .h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_spaghettiplot( label = "Spaghetti Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), idvar = "USUBJID", xaxis_var = variables(c("AVISITCD", "AVISIT"), "AVISITCD"), yaxis_var = variables(c("AVAL", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), color_comb = "#39ff14", man_color = c( "Combination" = "#000000", "Placebo" = "#fce300", "150mg QD" = "#5a2f5f" ), hline_arb = c(60, 50), hline_arb_color = c("grey", "red"), hline_arb_label = c("default A", "default B"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("pink", "brown", "purple", "black") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }# Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # use non-exported function from goshawk .h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value .arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- teal.data::rADSL ADLB <- teal.data::rADLB .var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(.arm_mapping[match(ARM, names(.arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(.arm_mapping[match(ACTARM, names(.arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD), ANRLO = 30, ANRHI = 75 ) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- .var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- .var_labels[["ACTARM"]] attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables ALB_LOQS <- .h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") }) join_keys(data) <- default_cdisc_join_keys[names(data)] app <- init( data = data, modules = modules( tm_g_gh_spaghettiplot( label = "Spaghetti Plot", dataname = "ADLB", param = picks( variables("PARAMCD", "PARAMCD"), values(selected = "ALT", multiple = FALSE), check_dataset = FALSE ), idvar = "USUBJID", xaxis_var = variables(c("AVISITCD", "AVISIT"), "AVISITCD"), yaxis_var = variables(c("AVAL", "CHG", "PCHG"), "AVAL"), trt_group = variables(c("ARM", "ACTARM"), "ARM"), color_comb = "#39ff14", man_color = c( "Combination" = "#000000", "Placebo" = "#fce300", "150mg QD" = "#5a2f5f" ), hline_arb = c(60, 50), hline_arb_color = c("grey", "red"), hline_arb_label = c("default A", "default B"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("pink", "brown", "purple", "black") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }