insightsengineering / tern

Table, Listings, and Graphs (TLG) library for common outputs used in clinical trials
https://insightsengineering.github.io/tern/
Other
77 stars 22 forks source link

[Bug]: Error in `decorate_grob` in one of the modules from the teal gallery #1184

Closed vedhav closed 9 months ago

vedhav commented 9 months ago

What happened?

The Efficacy app uses the tm_g_forest_tte() in which the call to decorate_grob is made which is causing this error:

Warning: Error in : only 'grobs' allowed in "gList"
 when evaluating qenv code:
p <- decorate_grob(g_forest(tbl = result, col_symbol_size = NULL), titles = c("Forest Plot of Survival Duration for OS: Overall Survival", "Stratified by STRATA1"), footnotes = "", gp_footnotes = grid::gpar(fontsize = 12))
  126: <Anonymous>
  125: stop
  124: [[.qenv.error
  122: <reactive>
  106: plot_r
   97: renderUI
   96: func
   83: renderFunc
   82: output$teal-main_ui-root-forest_plots-Survival_Forest_Plot-module-myplot-plot_out_main
    1: shiny::runApp

Here's a reproducible teal app with this error:

library(teal.modules.clinical)

data <- teal_data()
data <- within(data, {
  library(dplyr)
  library(scda)
  library(scda.2022)
  library(nestcolor)
  library(sparkline)

  ADSL <- synthetic_cdisc_data("latest")$adsl
  adsl_labels <- teal.data::col_labels(ADSL, fill = FALSE)
  char_vars_asl <- names(Filter(isTRUE, sapply(ADSL, is.character)))
  adsl_labels <- c(
    adsl_labels,
    AGEGR1 = "Age Group"
  )
  ADSL <- ADSL %>%
    mutate(
      AGEGR1 = factor(case_when(
        AGE < 45 ~ "<45",
        AGE >= 45 ~ ">=45"
      ))
    ) %>%
    mutate_at(char_vars_asl, factor)
  teal.data::col_labels(ADSL) <- adsl_labels
  ADTTE <- synthetic_cdisc_data("latest")$adtte
})

datanames <- c("ADSL", "ADTTE")
datanames(data) <- datanames

join_keys(data) <- default_cdisc_join_keys[datanames]

ADSL <- data[["ADSL"]]
ADTTE <- data[["ADTTE"]]

app <- init(
  data = data,
  filter = teal_slices(
    count_type = "all",
    teal_slice(dataname = "ADSL", varname = "ITTFL", selected = "Y"),
    teal_slice(dataname = "ADSL", varname = "SEX"),
    teal_slice(dataname = "ADSL", varname = "AGE")
  ),
  modules = tm_g_forest_tte(
    label = "Survival Forest Plot",
    dataname = "ADTTE",
    arm_var = choices_selected(
      choices = variable_choices(ADSL, subset = c("ARMCD", "ARM")),
      selected = "ARM"
    ),
    strata_var = choices_selected(
      choices = variable_choices(ADSL, subset = c("STRATA1", "STRATA2")),
      selected = "STRATA1"
    ),
    subgroup_var = choices_selected(
      choices = variable_choices(ADSL, subset = c("AGEGR1", "BMRKR2", "SEX", "COUNTRY")),
      selected = "AGEGR1"
    ),
    paramcd = choices_selected(
      choices = value_choices(ADTTE, "PARAMCD", "PARAM"),
      selected = "OS"
    ),
    plot_height = c(800L, 200L, 4000L)
  )
)

shinyApp(app$ui, app$server)

sessionInfo()

R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Asia/Kolkata
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] sparkline_2.0                     nestcolor_0.1.2.9007             
 [3] scda.2022_0.1.5.9004              scda_0.1.6.9014                  
 [5] dplyr_1.1.4                       teal.modules.clinical_0.8.16.9042
 [7] tern_0.9.3.9010                   rtables_0.6.6.9006               
 [9] formatters_0.5.5.9007             teal.transform_0.4.0.9015        
[11] magrittr_2.0.3                    teal_0.14.0.9041                 
[13] teal.slice_0.4.0.9040             teal.data_0.4.0.9000             
[15] teal.code_0.5.0.9002              shiny_1.8.0                      

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0         viridisLite_0.4.2        farver_2.1.1            
 [4] lazyeval_0.2.2           fastmap_1.1.1            TH.data_1.1-2           
 [7] promises_1.2.1           shinyjs_2.1.0            digest_0.6.34           
[10] estimability_1.4.1       mime_0.12                tern.gee_0.1.3.9000     
[13] lifecycle_1.0.4          ellipsis_0.3.2           survival_3.5-7          
[16] compiler_4.3.2           rlang_1.1.3              sass_0.4.8              
[19] tools_4.3.2              yaml_2.3.8               utf8_1.2.4              
[22] data.table_1.15.0        knitr_1.45               labeling_0.4.3          
[25] htmlwidgets_1.6.4        multcomp_1.4-25          withr_3.0.0             
[28] purrr_1.0.2              shinyWidgets_0.8.1       geepack_1.3.9           
[31] grid_4.3.2               fansi_1.0.6              teal.logger_0.1.3.9010  
[34] xtable_1.8-4             colorspace_2.1-0         ggplot2_3.4.4           
[37] emmeans_1.10.0           scales_1.3.0             MASS_7.3-60.0.1         
[40] cli_3.6.2                mvtnorm_1.2-4            crayon_1.5.2            
[43] rmarkdown_2.25           generics_0.1.3           httr_1.4.7              
[46] cachem_1.0.8             splines_4.3.2            assertthat_0.2.1        
[49] formatR_1.14             vctrs_0.6.5              Matrix_1.6-5            
[52] sandwich_3.1-0           jsonlite_1.8.8           teal.widgets_0.4.2.9002 
[55] plotly_4.10.4            fontawesome_0.5.2        tidyr_1.3.1             
[58] jquerylib_0.1.4          glue_1.7.0               codetools_0.2-19        
[61] cowplot_1.1.3            stringi_1.8.3            gtable_0.3.4            
[64] later_1.3.2              shinycssloaders_1.0.0    munsell_0.5.0           
[67] tibble_3.2.1             logger_0.2.2             pillar_1.9.0            
[70] htmltools_0.5.7          R6_2.5.1                 Rdpack_2.6              
[73] evaluate_0.23            lattice_0.22-5           rbibutils_2.2.16        
[76] backports_1.4.1          memoise_2.0.1            broom_1.0.5             
[79] teal.reporter_0.2.1.9017 httpuv_1.6.14            bslib_0.6.1             
[82] Rcpp_1.0.12              shinyvalidate_0.1.3      nlme_3.1-164            
[85] checkmate_2.3.1          xfun_0.41                zoo_1.8-12              
[88] pkgconfig_2.0.3

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

edelarua commented 9 months ago

Hi @vedhav,

I believe this is because of the g_forest refactor in tern. We reverted the updates to support the refactored version in TMC so that when TMC is added to CRAN it works with the version of tern that is available on CRAN (0.9.3), but this is scheduled to be fixed after the TMC CRAN release (see https://github.com/insightsengineering/teal.modules.clinical/pull/925).

If needed, the teal.gallery app should run fine with tern 0.9.3 if we lock the version in the meantime.

vedhav commented 9 months ago

Got it, thanks for the explanation. Closing this issue as it's a known bug and is being tracked. I also confirm that it's working fine after using the tern v0.9.3