Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: tm_t_summary() Error: Treatment values cannot contain empty strings #1225

Open
3 tasks done
botsp opened this issue Sep 12, 2024 · 0 comments
Open
3 tasks done
Labels
question Further information is requested

Comments

@botsp
Copy link

botsp commented Sep 12, 2024

What is your question?

The tm_t_summary requires that the input dataset cannot contain observations with empty ARM, otherwise the above ERROR will be reported. I tried to filter the data with filter = teal_slices(), but even though it's locked in the filter panel, it still shows an error.

A little confused about how to properly filter data for tm_t_summary. Many thanks!

I made more tests and also learned filter_panel_api, t it's true that teal_slice(dataname = "ADSL",expr="ARMCD=='ARM A'",id = "valid_arm", title = "Test NullARM") can pass the filter to tm_t_summary(); But it's a special case, if ADSL$ARM contains null value, this module tm_t_summary() failed to process it, wish for your further confirmation?


## Setup App
app <- teal::init(
  data = data,
  title = build_app_title("Safety Analysis Teal Demo App", nest_logo),
  header = header,
  footer = footer,
  # Set initial filter state as safety-evaluable population
  filter = teal_slices(
    count_type = "all",
    teal_slice(dataname = "ADSL", varname = "SAFFL", selected = "Y"),
    teal_slice(dataname = "ADSL",expr="ARMCD=='ARM A'",id = "valid_arm", title = "Test NullARM"),
    module_specific = TRUE,
    mapping = list(
      `Demographic Table` = "valid_arm"
    )
  ),
  modules = modules(
    tm_t_summary(
      label = "Demographic Table",
      dataname = "ADSL",
      arm_var =   choices_selected("ARM", "ARM"),
      summarize_vars = choices_selected(
        c("SEX", "RACE", "AGE"),
        selected = c("SEX", "AGE", "RACE")
      )
    )
  )
)

image

Click to toggle contents of `Full code`, Copy and run directly
library(teal.modules.general)
library(teal.modules.clinical)
options(shiny.useragg = FALSE)

## Data reproducible code ----

data <- within(teal_data(), {
  library(random.cdisc.data)
  library(dplyr)
  library(nestcolor)
  # optional libraries
  library(sparkline)
  
  ADSL <- radsl(seed = 1)
  ADSL <- ADSL %>%
    mutate(ARM = as.character(ARM)) %>%
    mutate(ARM = ifelse(ARM == "C: Combination", "", ARM)) %>%
    mutate(ARM = as.factor(ARM))
})

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


## App header and footer ----
nest_logo <- "https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/nest.png"
app_source <- "https://github.com/insightsengineering/teal.gallery/tree/main/safety"
gh_issues_page <- "https://github.com/insightsengineering/teal.gallery/issues"

header <- tags$span(
  style = "display: flex; align-items: center; justify-content: space-between; margin: 10px 0 10px 0;",
  tags$span("My first teal app", style = "font-size: 30px;"),
  tags$span(
    style = "display: flex; align-items: center;",
    tags$img(src = nest_logo, alt = "NEST logo", height = "45px", style = "margin-right:10px;"),
    tags$span(style = "font-size: 24px;", "NEST @ Roche")
  )
)

footer <- tags$p(
  "This teal app is brought to you by the NEST Team at Roche/Genentech.
        For more information, please visit:",
  tags$a(href = app_source, target = "_blank", "Source Code"), ", ",
  tags$a(href = gh_issues_page, target = "_blank", "Report Issues")
)

## Setup App
app <- teal::init(
  data = data,
  title = build_app_title("Safety Analysis Teal Demo App", nest_logo),
  header = header,
  footer = footer,
  # Set initial filter state as safety-evaluable population
  filter = teal_slices(
    count_type = "all",
    teal_slice(dataname = "ADSL", varname = "SAFFL", selected = "Y"),
    teal_slice(dataname = "ADSL",expr="ARMCD=='ARM A'",id = "valid_arm", title = "Test NullARM"),
    teal_slice(dataname = "ADSL", varname = "AGE"),
    module_specific = TRUE,
    mapping = list(
      `Demographic Table` = "valid_arm"
    )
  ),
  modules = modules(
    tm_front_page(
      label = "App Info",
      header_text = c("Info about input data source" = "This app uses CDISC ADaM datasets randomly generated by `random.cdisc.data` R packages"),
      tables = list(`NEST packages used in this demo app` = data.frame(
        Packages = c(
          "teal.modules.general",
          "teal.modules.clinical",
          "random.cdisc.data"
        )
      ))
    ),
    tm_data_table("Data Table"),
    tm_variable_browser("Variable Browser"),
    tm_t_summary(
      label = "Demographic Table",
      dataname = "ADSL",
      arm_var =   choices_selected("ARM", "ARM"),
      summarize_vars = choices_selected(
        c("SEX", "RACE", "AGE"),
        selected = c("SEX", "AGE", "RACE")
      )
    )
  )
)

shinyApp(app$ui, app$server)

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@botsp botsp added the question Further information is requested label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant