insightsengineering / teal.reporter

Create and preview reports with Shiny modules
https://insightsengineering.github.io/teal.reporter/
Other
8 stars 9 forks source link

[Bug]: Can not create Report Card for `teal.modules.clinical::tm_g_pp_patient_timeline` #196

Closed m7pr closed 11 months ago

m7pr commented 11 months ago

What happened?

image

I run the above issue while playing with teal.gallery app called patient-profile that is hosted on shinyapps. https://genentech.shinyapps.io/nest_patient-profile_main/ -> Patient timeline module.

The error that I see locally, when running a simplified app

Listening on http://127.0.0.1:7844
Error in parse_safely(text, keep.source = TRUE) : 
  <text>:63:1: unexpected 'else'
62: }
63: else
    ^
Warning in observe() :
  The card could not be added to the report. Have the outputs for the report been created yet? If not please try again when they are ready. Otherwise contact your application developer

Code to reproduce the issue - run below + try to create a card

library(teal.modules.clinical)
library(teal.modules.general)
library(scda)
library(scda.2022)
library(nestcolor)

options(shiny.useragg = FALSE)

ADSL <- synthetic_cdisc_data("latest")$adsl
ADMH <- synthetic_cdisc_data("latest")$admh
ADAE <- synthetic_cdisc_data("latest")$adae
ADCM <- synthetic_cdisc_data("latest")$adcm
ADVS <- synthetic_cdisc_data("latest")$advs
ADLB <- synthetic_cdisc_data("latest")$adlb

## Modify ADCM
ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD))
ADCM$CMDOSE <- 1
ADCM$CMTRT <- ADCM$CMCAT
ADCM$CMDOSU <- "U"
ADCM$CMROUTE <- "CMROUTE"
ADCM$CMDOSFRQ <- "CMDOSFRQ"
ADCM$CMASTDTM <- ADCM$ASTDTM
ADCM$CMAENDTM <- ADCM$AENDTM

teal.data::col_labels(
  ADCM[c("CMINDC", "CMTRT", "ASTDY", "AENDY")]
) <- c(
  "Indication",
  "Reported Name of Drug, Med, or Therapy",
  "Study Day of Start of Medication",
  "Study Day of End of Medication"
)

## Modify ADHM
ADMH[["MHDISTAT"]] <- "ONGOING"
teal.data::col_labels(ADMH[c("MHDISTAT")]) <- c("Status of Disease")

## Define variable inputs
aeterm_input <- data_extract_spec(
  dataname = "ADAE",
  select = select_spec(
    choices = variable_choices(ADAE, "AETERM"),
    selected = c("AETERM"),
    multiple = FALSE,
    fixed = FALSE
  )
)

cmtrt_input <- data_extract_spec(
  dataname = "ADCM",
  select = select_spec(
    choices = variable_choices(ADCM, "CMTRT"),
    selected = c("CMTRT"),
    multiple = FALSE,
    fixed = FALSE
  )
)

cmindc_input <- data_extract_spec(
  dataname = "ADCM",
  select = select_spec(
    choices = variable_choices(ADCM, "CMINDC"),
    selected = c("CMINDC"),
    multiple = FALSE,
    fixed = FALSE
  )
)

atirel_input <- data_extract_spec(
  dataname = "ADCM",
  select = select_spec(
    choices = variable_choices(ADCM, "ATIREL"),
    selected = c("ATIREL"),
    multiple = FALSE,
    fixed = FALSE
  )
)

cmdecod_input <- data_extract_spec(
  dataname = "ADCM",
  select = select_spec(
    choices = variable_choices(ADCM, "CMDECOD"),
    selected = c("CMDECOD"),
    multiple = FALSE,
    fixed = FALSE
  )
)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", ADSL, code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"),
    cdisc_dataset("ADAE", ADAE, code = "ADAE <- synthetic_cdisc_data(\"latest\")$adae"),
    cdisc_dataset("ADMH", ADMH, code = "ADMH <- synthetic_cdisc_data(\"latest\")$admh
      ADMH[['MHDISTAT']] <- 'ONGOING'
      teal.data::col_labels(ADMH[c('MHDISTAT')]) <- c('Status of Disease')"),
    cdisc_dataset("ADCM", ADCM, code = 'ADCM <- synthetic_cdisc_data(\"latest\")$adcm
      ADCM$CMINDC <- paste0("Indication_", as.numeric(ADCM$CMDECOD))
      ADCM$CMDOSE <- 1
      ADCM$CMTRT <- ADCM$CMCAT
      ADCM$CMDOSU <- "U"
      ADCM$CMROUTE <- "CMROUTE"
      ADCM$CMDOSFRQ <- "CMDOSFRQ"
      ADCM$CMASTDTM <- ADCM$ASTDTM
      ADCM$CMAENDTM <- ADCM$AENDTM
      teal.data::col_labels(
        ADCM[c("CMINDC", "CMTRT", "ASTDY", "AENDY")]) <- c(
          "Indication",
          "Reported Name of Drug, Med, or Therapy",
          "Study Day of Start of Medication",
          "Study Day of End of Medication")'),
    cdisc_dataset("ADVS", ADVS, code = "ADVS <- synthetic_cdisc_data(\"latest\")$advs"),
    cdisc_dataset("ADLB", ADLB, code = "ADLB <- synthetic_cdisc_data(\"latest\")$adlb"),
    check = TRUE
  ),
  modules = modules(
    tm_g_pp_patient_timeline(
      label = "Patient timeline",
      parentname = "ADSL",
      patient_col = "USUBJID",
      plot_height = c(600L, 200L, 2000L),
      font_size = c(15L, 8L, 25L),
      cmdecod = cmdecod_input,
      aeterm = aeterm_input,
      aetime_start = data_extract_spec(
        dataname = "ADAE",
        select = select_spec(
          choices = variable_choices(ADAE, "ASTDTM"),
          selected = c("ASTDTM"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      aetime_end = data_extract_spec(
        dataname = "ADAE",
        select = select_spec(
          choices = variable_choices(ADAE, "AENDTM"),
          selected = c("AENDTM"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      dstime_start = data_extract_spec(
        dataname = "ADCM",
        select = select_spec(
          choices = variable_choices(ADCM, "CMASTDTM"),
          selected = c("CMASTDTM"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      dstime_end = data_extract_spec(
        dataname = "ADCM",
        select = select_spec(
          choices = variable_choices(ADCM, "CMAENDTM"),
          selected = c("CMAENDTM"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      aerelday_start = data_extract_spec(
        dataname = "ADAE",
        select = select_spec(
          choices = variable_choices(ADAE, "ASTDY"),
          selected = c("ASTDY"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      aerelday_end = data_extract_spec(
        dataname = "ADAE",
        select = select_spec(
          choices = variable_choices(ADAE, "AENDY"),
          selected = c("AENDY"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      dsrelday_start = data_extract_spec(
        dataname = "ADCM",
        select = select_spec(
          choices = variable_choices(ADCM, "ASTDY"),
          selected = c("ASTDY"),
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      dsrelday_end = data_extract_spec(
        dataname = "ADCM",
        select = select_spec(
          choices = variable_choices(ADCM, "AENDY"),
          selected = c("AENDY"),
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )

  ),
  header = div(
    class = "",
    style = "margin-bottom: 2px;",
    tags$h1("Example Patient Profile App", tags$span("SPA", class = "pull-right"))
  ),
  footer = tags$p(class = "text-muted", "Source: teal.gallery package")
)

shinyApp(app$ui, app$server)

sessionInfo()

sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_Europe.utf8  LC_CTYPE=English_Europe.utf8    LC_MONETARY=English_Europe.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Europe.utf8    

time zone: Europe/Berlin
tzcode source: internal

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

other attached packages:
 [1] nestcolor_0.1.2.9001              scda.2022_0.1.5.9000              scda_0.1.6.9008                  
 [4] teal.modules.general_0.2.15.9027  shinyTree_0.2.7                   ggmosaic_0.3.3                   
 [7] ggplot2_3.4.2                     teal.modules.clinical_0.8.15.9009 tern_0.8.4.9005                  
[10] rtables_0.6.2.9000                formatters_0.5.1.9000             teal_0.13.0.9017                 
[13] teal.transform_0.3.0.9008         magrittr_2.0.3                    teal.slice_0.3.0.9020            
[16] teal.data_0.2.0.9006              shiny_1.7.4.1                    

loaded via a namespace (and not attached):
 [1] Rdpack_2.4               tern.gee_0.1.0.9006      logger_0.2.2             rlang_1.1.1             
 [5] teal.code_0.3.0.9007     compiler_4.3.0           systemfonts_1.0.4        vctrs_0.6.2             
 [9] stringr_1.5.0            pkgconfig_2.0.3          crayon_1.5.2             fastmap_1.1.1           
[13] backports_1.4.1          ellipsis_0.3.2           fontawesome_0.5.1        labeling_0.4.2          
[17] utf8_1.2.3               promises_1.2.0.1         rmarkdown_2.23           ragg_1.2.5              
[21] purrr_1.0.1              xfun_0.39                shinyvalidate_0.1.2      cachem_1.0.8            
[25] teal.reporter_0.1.1.9018 jsonlite_1.8.4           later_1.3.1              styler_1.10.1           
[29] broom_1.0.5              R6_2.5.1                 bslib_0.5.0              stringi_1.7.12          
[33] jquerylib_0.1.4          estimability_1.4.1       Rcpp_1.0.10              assertthat_0.2.1        
[37] knitr_1.43               teal.logger_0.1.1.9007   R.utils_2.12.2           httpuv_1.6.11           
[41] Matrix_1.5-4             splines_4.3.0            R.cache_0.16.0           tidyselect_1.2.0        
[45] rstudioapi_0.15.0        yaml_2.3.7               teal.widgets_0.3.0.9004  lattice_0.21-8          
[49] tibble_3.2.1             withr_2.5.0              evaluate_0.21            survival_3.5-5          
[53] pillar_1.9.0             checkmate_2.2.0          DT_0.28                  shinyjs_2.1.0           
[57] plotly_4.10.2            generics_0.1.3           munsell_0.5.0            scales_1.2.1            
[61] xtable_1.8-4             glue_1.6.2               emmeans_1.8.7            lazyeval_0.2.2          
[65] tools_4.3.0              data.table_1.14.8        mvtnorm_1.2-2            grid_4.3.0              
[69] tidyr_1.3.0              rbibutils_2.2.13         crosstalk_1.2.0          colorspace_2.1-0        
[73] nlme_3.1-162             cli_3.6.1                textshaping_0.3.6        fansi_1.0.4             
[77] viridisLite_0.4.2        geepack_1.3.9            dplyr_1.1.2              gtable_0.3.3            
[81] R.methodsS3_1.8.2        sass_0.4.7               digest_0.6.31            ggrepel_0.9.3           
[85] htmlwidgets_1.6.2        farver_2.1.1             memoise_2.0.1            htmltools_0.5.5         
[89] R.oo_1.25.0              lifecycle_1.0.3          httr_1.4.6               shinyWidgets_0.7.6      
[93] mime_0.12                MASS_7.3-58.4

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy