insightsengineering / teal

Exploratory Web Apps for Analyzing Clinical Trial Data
https://insightsengineering.github.io/teal/
Other
171 stars 34 forks source link

[Bug]: Error when using tm_g_response on child dataset combined with teal.slice filters #1125

Closed parmsam-pfizer closed 6 months ago

parmsam-pfizer commented 6 months ago

What happened?

Running into an error when using tm_g_response on a child dataset combined with use of teal.slice filters. Error and code included below. Works when using tm_g_response and module filters applied to ADSL dataset (the main parent dataset), but anytime the tm_g_response module is used on a child dataset and there are filters it fails. Not sure if I'm misusing the new version of teal.slice but this sort of thing worked in previous package versions.

[INFO] 2024-03-04 14:48:47.7540 pid:1180 token:[] teal.modules.clinical Initializing tm_t_summary
[INFO] 2024-03-04 14:48:47.7587 pid:1180 token:[] teal.modules.general Initializing tm_g_response
[INFO] 2024-03-04 14:48:47.7675 pid:1180 token:[] teal.modules.general Initializing tm_g_response

Listening on http://127.0.0.1:3594
[INFO] 2024-03-04 14:48:49.6267 pid:1180 token:[dfa8ffb0] teal Initializing reporter_previewer_module
Warning: Error in self$get_data: Assertion on 'dataname' failed: Must be a subset of the empty set, i.e. also empty.
  1: runApp
library(teal)
library(teal.modules.general)
library(teal.modules.clinical)
library(teal.slice)

ADSL <- teal.modules.clinical::tmc_ex_adsl
ADAE <- teal.modules.clinical::tmc_ex_adae
ADTTE <- teal.modules.clinical::tmc_ex_adtte

data <- cdisc_data(
  ADSL = ADSL,
  ADAE = ADAE,
  ADTTE = ADTTE
)

datanames <- c("ADSL", "ADAE", "ADTTE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]

app <- init(
  data = data,
  modules = modules(
    tm_t_summary(
      label = "Demographic Table 2", 
      dataname = "ADSL",
      arm_var = choices_selected(choices = c("ARM", "ARMCD"), selected = "ARM"),
      summarize_vars = choices_selected(
        choices = c("SEX", "RACE", "BMRKR2", "EOSDY", "DCSREAS", "AGE"),
        selected = c("SEX", "RACE")
      )
    ),
    # ERROR when using child dataset with this module and module_specific teal_slice filters but works on parent dataset
    tm_g_response(
      label = "Response Plots ADAE",
      response = data_extract_spec(
        dataname = "ADAE",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(ADAE, c("BMRKR2")),
          selected = "BMRKR2",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      x = data_extract_spec(
        dataname = "ADAE",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(ADAE, c("SEX", "RACE")),
          selected = "RACE",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      ggplot2_args = teal.widgets::ggplot2_args(
        labs = list(subtitle = "Plot generated by Response Module")
      )
      , ggtheme = "bw"
    ),
    tm_g_response(
      label = "Response Plots ADSL",
      response = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(ADSL, c("BMRKR2", "COUNTRY")),
          selected = "BMRKR2",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      x = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(ADSL, c("SEX", "RACE")),
          selected = "RACE",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      ggplot2_args = teal.widgets::ggplot2_args(
        labs = list(subtitle = "Plot generated by Response Module")
      )
      , ggtheme = "bw"
    )
  ),
  filter = teal_slices(
    teal_slice("ADAE", "SAFFL", id = "saffl", selected = "Y", fixed = TRUE, anchored = TRUE),
    teal_slice("ADAE", id = "aerel", expr = "AEREL == 'Y' & AETOXGR %in% c('3', '4', '5')", title = "Grade 3+ Related Events"),
    module_specific = TRUE,
    mapping = list(
      "Demographic Table 2" = c("aerel"),
      "Response Plots ADAE" = c("saffl")
    )
  )
)

shinyApp(app$ui, app$server)

sessionInfo()

No response

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy