insightsengineering / teal.modules.general

General Purpose Teal Modules
https://insightsengineering.github.io/teal.modules.general/
Other
9 stars 13 forks source link

Update tm_g_distribution.R #766

Closed saerobson closed 2 months ago

saerobson commented 3 months ago

I have made a direct PR as it was recommended for such small updates. Fix distribution default parameters when multiple data_extract_spec's are specified. Documentation states that multiple data_extract_spec’s can be specified so this solution makes this work.

Problem: https://github.com/user-attachments/assets/08e0a0b6-3e26-4d2b-97c7-82c9feaa0ad0

Solution: https://github.com/user-attachments/assets/b9cd2122-4cb6-4913-90cb-bb67c185693e

github-actions[bot] commented 3 months ago

✅ All contributors have signed the CLA
Posted by the CLA Assistant Lite bot.

saerobson commented 3 months ago

I have read the CLA Document and I hereby sign the CLA

donyunardi commented 3 months ago

@saerobson Thanks for providing a video on the problem. Can I also ask for the code that you use so I can reproduce the issue?

sarah-robson commented 3 months ago

Please find the code below to create the broken app video.

# library
library(shiny)
library(teal)
library(teal.widgets)
library(teal.modules.general)
library(teal.logger)

# global variables
ggplot_themes <- c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void")
interactive <- NULL

# CDISC data example
data <- teal_data()
data <- within(data, {
  ADSL <- rADSL
  ADVS <- rADVS
})
datanames(data) <- c("ADSL", "ADVS")
join_keys(data) <- default_cdisc_join_keys[datanames(data)]

vars1 <- choices_selected(
  variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
  selected = NULL
)

# data_extract_specs
dist_var_adsl = data_extract_spec(
  dataname = "ADSL",
  select = select_spec(
    choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
    selected = "BMRKR1",
    multiple = FALSE,
    fixed = FALSE
  )
)

dist_var_advs = data_extract_spec(
  dataname = "ADVS",
  select = select_spec(
    choices = variable_choices(data[["ADVS"]], c("AVAL")),
    selected = "AVAL",
    multiple = FALSE,
    fixed = FALSE
  )
)

# app
app <- init(
  data = data,
  modules = modules(
    tm_g_distribution(
      dist_var = list(dist_var_adsl,
                      dist_var_advs
      ),
      strata_var = data_extract_spec(
        dataname = "ADSL",
        filter = filter_spec(
          vars = vars1,
          multiple = TRUE
        )
      ),
      group_var = data_extract_spec(
        dataname = "ADSL",
        filter = filter_spec(
          vars = vars1,
          multiple = TRUE
        )
      ),
      ggplot2_args = ggplot2_args(
        labs = list(subtitle = "Plot generated by Distribution Module")
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}
Polkas commented 2 months ago

@gogonzo Please help us with the review:)

gogonzo commented 2 months ago

Thanks @saerobson