insightsengineering / teal.osprey

Community efforts to collect teal modules for TLGs defined in the osprey package
https://insightsengineering.github.io/teal.osprey/
Other
5 stars 2 forks source link

[Bug]: I cannot apply filter to tm_g_waterfall #271

Closed nsteed15 closed 4 months ago

nsteed15 commented 4 months ago

What happened?

When I try applying the filter of ANL03FL = 'Y' I get this error. I get this when trying to add the filter for any of the variable ANL01FL or ANL02FL.

image

Here is my module code

tm_g_spiderplot(
        label = "Spider plot",
        dataname = "ADTR",
        paramcd = choices_selected(choices = c("TLD1", "TLD2", "TLD3", "TLD4", "TLD5", "TSD",  "TLP2", "TLP3", "TLP1", "TLP4", "TLP5"),
          selected = "TSD"
        ),
        x_var = choices_selected(choices = "ADY", selected = "ADY"),
        y_var = choices_selected(
          choices = c("PCHG", "CHG", "AVAL"),
          selected = "PCHG"
        ),
        marker_var = choices_selected(
          choices = c("SEX", "RACE", "USUBJID"),
          selected = "SEX"
        ),
        line_colorby_var = choices_selected(
          choices = c("TRT01P", "TRT01A", "ARMCD", "ACTARMCD"),
          selected = "TRT01P"
        ),
        xfacet_var = choices_selected(
          choices = c("SEX", "RACE", "ETHNIC", "COUNTRY", "AGEGR1", "STRAT1R", "STRAT1V"),
          selected = NULL
        ),
        yfacet_var = choices_selected(
          choices = c("SEX", "RACE", "ETHNIC", "COUNTRY", "AGEGR1", "STRAT1R", "STRAT1V"),
          selected = NULL
        ),
        vref_line = "42",
        href_line = "-20, 0, 30"
      )

I am trying to apply the anl03fl to this module

 filter = teal_slices(
    # filters created with id
    teal_slice(dataname = "ADRS", keep_na = FALSE, varname = 'AVALC', selected =  c("CR", "PR", "SD", "PD", 'NE'), id = "adrs_rm_na", title = 'ADRS AVALC Filter'),
    teal_slice(dataname = 'ADSL', keep_na = FALSE, varname = 'RAN105FL', selected = c('Y'), id = '105 Patients'),
    teal_slice(dataname = "ADAE", id = "aeacn", expr = "AEACN1 == 'DRUG WITHDRAWN' | AEACN2 == 'DRUG WITHDRAWN' | AEACN3 == 'DRUG WITHDRAWN' | AEACN4 == 'DRUG WITHDRAWN'", title = "Drug Withdrawn"),
    teal_slice(dataname = 'ADSL', keep_na = FALSE, varname = 'TRTA', selected = c("Pembro+Axi", "Tobe+Axi", "Tobe+Tira+Axi"), id = 'trta', title = 'TRTA Filter'),
    teal_slice(dataname = 'ADSL', keep_na = FALSE, varname = 'EEFL', selected = c('Y'), id = 'eefl', title = 'EEFL Flag'),
    teal_slice(dataname = 'ADTR', keep_na = FALSE, varname = 'ANL03FL', selected = c('Y'), id = 'anl03fl', title = 'ANL03FL'),
    # module-specific filtering enabled
    module_specific = TRUE,
    # filters mapped to modules
    mapping = list(
      'Response Table' = c('105 Patients', 'trta', 'eefl'),
      'Time To Event Table' = '105 Patients',
      "Kaplan Meier Plot" = '105 Patients',
      "AE Leading to Discontinuation" = c('aeacn', 'trta'),
      "Disposition Table" = '105 Patients', 
      "Immune-mediated Adverse Events" = 'trta',
      "AE Table by Grade" = 'trta',
      "AE by Term" = 'trta',
      "Demographic Table" = '105 Patients',
      "Waterfall Plot" = 'anl03fl'

      # 'Adverse Events' = 'trta'
    )
  ),

sessionInfo()

R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=C               LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: UTC
tzcode source: system (glibc)

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

other attached packages:
 [1] sparkline_2.0               teal.osprey_0.1.16.9019     osprey_0.1.16              
 [4] teal.connectors.rice_0.2.0  teal.modules.clinical_0.9.1 tern_0.9.4                 
 [7] rtables_0.6.7               magrittr_2.0.3              formatters_0.5.6           
[10] teal.modules.general_0.3.0  teal.transform_0.5.0        ggmosaic_0.3.3             
[13] ggplot2_3.5.1               teal_0.15.2.9039            teal.slice_0.5.1           
[16] teal.data_0.6.0             teal.code_0.5.0             shiny_1.8.1.1              
[19] dplyr_1.1.4                

loaded via a namespace (and not attached):
 [1] Rdpack_2.6               tern.gee_0.1.3           logger_0.3.0             rlang_1.1.3             
 [5] rice_3.0.1               compiler_4.3.1           getPass_0.2-4            vctrs_0.6.5             
 [9] stringr_1.5.1            crayon_1.5.2             pkgconfig_2.0.3          fastmap_1.1.1           
[13] backports_1.4.1          labeling_0.4.3           fontawesome_0.5.2        utf8_1.2.4              
[17] promises_1.3.0           rmarkdown_2.26           tzdb_0.4.0               haven_2.5.4             
[21] purrr_1.0.2              xfun_0.43                shinyvalidate_0.1.3      cachem_1.0.8            
[25] labelled_2.13.0          teal.reporter_0.3.1.9007 jsonlite_1.8.8           later_1.3.2             
[29] broom_1.0.5              R6_2.5.1                 bslib_0.7.0              stringi_1.8.3           
[33] ricepass_1.1.4           jquerylib_0.1.4          estimability_1.5         Rcpp_1.0.12             
[37] assertthat_0.2.1         knitr_1.46               teal.logger_0.2.0        base64enc_0.1-3         
[41] readr_2.1.5              httpuv_1.6.15            Matrix_1.6-1.1           splines_4.3.1           
[45] tidyselect_1.2.1         rstudioapi_0.16.0        yaml_2.3.8               curl_5.2.1              
[49] teal.widgets_0.4.2       lattice_0.22-6           tibble_3.2.1             withr_3.0.0             
[53] askpass_1.2.0            evaluate_0.23            survival_3.6-4           pillar_1.9.0            
[57] shinycssloaders_1.0.0    rsconnect_1.2.2          checkmate_2.3.1          renv_1.0.7              
[61] shinyjs_2.1.0            plotly_4.10.4            generics_0.1.3           hms_1.1.3               
[65] munsell_0.5.1            scales_1.3.0             xtable_1.8-4             glue_1.7.0              
[69] emmeans_1.10.1           lazyeval_0.2.2           tools_4.3.1              data.table_1.15.4       
[73] forcats_1.0.0            mvtnorm_1.2-4            grid_4.3.1               tidyr_1.3.1             
[77] rbibutils_2.2.16         colorspace_2.1-0         nlme_3.1-164             cli_3.6.2               
[81] fansi_1.0.6              viridisLite_0.4.2        geepack_1.3.10           gtable_0.3.5            
[85] sass_0.4.9               digest_0.6.35            ggrepel_0.9.5            farver_2.1.1            
[89] htmlwidgets_1.6.4        memoise_2.0.1            htmltools_0.5.8.1        lifecycle_1.0.4         
[93] PKI_0.1-12               httr_1.4.7               shinyWidgets_0.8.6       mime_0.12               
[97] openssl_2.1.2            MASS_7.3-60

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

nsteed15 commented 4 months ago

Hi @m7pr you helped me with a similar error. I am wondering if you have any suggestions for me for this?

vedhav commented 4 months ago

Hello @Nolan-Steed, It looks like an issue with the filter panel, not the module. This was already logged and fixed. However, this fix is only available in the development version of teal.slice 0.5.1.9001 and above.

Currently, the recommendation is not to have empty strings in the columns of your datasets. You can use the tern::df_explicit_na function to convert all the "" into <Missing> or something that will not type cast into NA. Once this change is made, it could fix this error in your app. Below you can find a snippet from Dony's comment:

x <- data.frame(
  a = factor(c("", "Y", "", "Y")),
  b = LETTERS[1:4]
)

x <- tern::df_explicit_na(x)
x
#>           a b
#> 1 <Missing> A
#> 2         Y B
#> 3 <Missing> C
#> 4         Y D
m7pr commented 4 months ago

you rock @vedhav

nsteed15 commented 4 months ago

Thank you @vedhav for your response. This fixes the issue I am having with my app.