insightsengineering / teal.data

Data model for teal applications
https://insightsengineering.github.io/teal.data/
Other
9 stars 8 forks source link

[teal.data] Reproducibility check incorrect message #4

Closed nikolas-burkoff closed 2 years ago

nikolas-burkoff commented 2 years ago
library(scda)
library(dplyr)
library(teal.modules.clinical)

adsl <- synthetic_cdisc_data("latest")$adsl
adex <- synthetic_cdisc_data("latest")$adex

set.seed(1, kind = "Mersenne-Twister")
adex <- adex %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  mutate(
    PARAMCD = "TDURD",
    PARAM = "Overall duration (days)",
    AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
    AVALU = "Days"
  ) %>%
  bind_rows(adex)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_data("latest")$adsl'),
    cdisc_dataset("ADEX", adex, code = 'ADEX <- synthetic_cdisc_data("latest")$adex
  set.seed(1, kind = "Mersenne-Twister")
  ADEX <- ADEX %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  mutate(PARAMCD = "TDURD",
         PARAM = "Overall duration (days)",
         AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
         AVALU = "Days") %>%
  bind_rows(ADEX)'),
    check = TRUE
  ),
  modules = modules(
    tm_t_exposure(
      label = "Duration of Exposure Table",
      dataname = "ADEX",
      paramcd = choices_selected(
        choices = value_choices(adex, "PARAMCD", "PARAM"),
        selected = "TDURD"
      ),
      col_by_var = choices_selected(
        choices = variable_choices(adex, subset = c("ARM")),
        selected = NULL
      ),
      row_by_var = choices_selected(
        choices = variable_choices(adex, subset = c("ETHNIC", "SEX")),
        selected = "ETHNIC"
      ),
      parcat = choices_selected(
        choices = value_choices(adex, "PARCAT2"),
        selected = "Drug A"
      ),
      add_total = FALSE
    )
  ),
  filter = list(
    ADSL = list(SAFFL = "Y")
  )
)

shinyApp(app$ui, app$server)

This has check = TRUE (and the reproducibility check does run - change the seed from 1 to 10 in the code argument) but you still see

image

Note also https://github.com/insightsengineering/teal.modules.clinical/issues/405

nikolas-burkoff commented 2 years ago

Example not requiring tmc:

library(scda)
library(dplyr)
library(teal)

adsl <- synthetic_cdisc_data("latest")$adsl
adex <- synthetic_cdisc_data("latest")$adex

set.seed(1, kind = "Mersenne-Twister")
adex <- adex %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  mutate(
    PARAMCD = "TDURD",
    PARAM = "Overall duration (days)",
    AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
    AVALU = "Days"
  ) %>%
  bind_rows(adex)

data <- cdisc_data(
  cdisc_dataset("ADSL", adsl, code = 'ADSL <- synthetic_cdisc_data("latest")$adsl'),
  cdisc_dataset("ADEX", adex, code = 'ADEX <- synthetic_cdisc_data("latest")$adex
  set.seed(1, kind = "Mersenne-Twister")
  ADEX <- ADEX %>%
  distinct(USUBJID, .keep_all = TRUE) %>%
  mutate(PARAMCD = "TDURD",
         PARAM = "Overall duration (days)",
         AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
         AVALU = "Days") %>%
  bind_rows(ADEX)'),
  check = TRUE
)

app <- init(
  data = data,
  modules = modules(
    module(
      "simple show r code",
      server = function(id, datasets) {
        moduleServer(id, function(input, output, session) {
          teal.code::init_chunks()
          output$text <- renderText("Text here")
          teal::get_rcode_srv(
            id = "rcode",
            datasets = datasets,
            datanames = c("ADSL", "ADEX"),
            modal_title = "R Code",
            code_header = "R Code"
          )
        })
      },
      ui = function(id, datasets) {
        ns <- NS(id)
        teal.widgets::standard_layout(
          output = textOutput(ns("text")),
          forms = teal::get_rcode_ui(ns("rcode"))
        )
      },
      filters = "all",
    )
  )
)

runApp(app)