Skip to contents

Display the AE overview plot as a shiny module

Usage

tm_g_ae_oview(
  label,
  dataname,
  arm_var,
  flag_var_anl,
  fontsize = c(5, 3, 7),
  plot_height = c(600L, 200L, 2000L),
  plot_width = NULL
)

Arguments

label

(character(1))
menu item label of the module in the teal app.

dataname

(character(1))
analysis data used in the teal module, needs to be available in the list passed to the data argument of teal::init().

arm_var

(choices_selected)
object with all available choices and the pre-selected option for variable names that can be used as arm_var. See teal.transform::choices_selected() for details.

flag_var_anl

(teal.transform::choices_selected) choices_selected object with variables used to count adverse event sub-groups (e.g. Serious events, Related events, etc.)

fontsize

(numeric(1) or numeric(3))
Defines initial possible range of font-size. fontsize is set for teal.widgets::optionalSliderInputValMinMax() which controls font-size in the output plot.

plot_height

(numeric(3))
vector to indicate default value, minimum and maximum values.

plot_width

(numeric(3))
vector to indicate default value, minimum and maximum values.

Value

the teal::module() object.

Examples

library(scda)
#> 

ADSL <- synthetic_cdisc_data("latest")$adsl
ADAE <- synthetic_cdisc_data("latest")$adae

# Add additional dummy causality flags.
add_event_flags <- function(dat) {
  dat <- dat %>%
    dplyr::mutate(
      TMPFL_SER = AESER == "Y",
      TMPFL_REL = AEREL == "Y",
      TMPFL_GR5 = AETOXGR == "5",
      AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X"),
      AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")
    )
  labels <- c(
    "Serious AE", "Related AE", "Grade 5 AE",
    "AE related to A: Drug X", "AE related to B: Placebo"
  )
  cols <- c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
  for (i in seq_along(labels)) {
    attr(dat[[cols[i]]], "label") <- labels[i]
  }
  dat
}
ADAE <- ADAE %>% add_event_flags()

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", ADSL, code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"),
    cdisc_dataset("ADAE", ADAE,
      code =
        "ADAE <- synthetic_cdisc_data('latest')$adae
           add_event_flags <- function(dat) {
             dat <- dat %>%
               dplyr::mutate(
                 TMPFL_SER = AESER == 'Y',
                 TMPFL_REL = AEREL == 'Y',
                 TMPFL_GR5 = AETOXGR == '5',
                 AEREL1 = (AEREL == 'Y' & ACTARM == 'A: Drug X'),
                 AEREL2 = (AEREL == 'Y' & ACTARM == 'B: Placebo')
               )
             labels <- c(
               'Serious AE',
               'Related AE',
               'Grade 5 AE',
               'AE related to A: Drug X',
               'AE related to B: Placebo'
             )
             cols <- c('TMPFL_SER', 'TMPFL_REL', 'TMPFL_GR5', 'AEREL1', 'AEREL2')
             for (i in seq_along(labels)) {
              attr(dat[[cols[i]]], 'label') <- labels[i]
             }
             dat
           }
           # Generating user-defined event flags.
           ADAE <- ADAE %>% add_event_flags()"
    ),
    check = TRUE
  ),
  modules = modules(
    tm_g_ae_oview(
      label = "AE Overview",
      dataname = "ADAE",
      arm_var = choices_selected(
        selected = "ACTARM",
        choices = c("ACTARM", "ACTARMCD")
      ),
      flag_var_anl = choices_selected(
        selected = "AEREL1",
        choices = variable_choices(
          ADAE,
          c("TMPFL_SER", "TMPFL_REL", "TMPFL_GR5", "AEREL1", "AEREL2")
        ),
      ),
      plot_height = c(600, 200, 2000)
    )
  )
)
#> [INFO] 2022-06-17 09:55:49.9414 pid:1163 token:[] teal.osprey Initializing tm_g_ae_oview
if (FALSE) {
shinyApp(app$ui, app$server)
}