Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: What do display when missing datasets passed to teal #1409

Open
gogonzo opened this issue Nov 13, 2024 · 0 comments
Open

[Question]: What do display when missing datasets passed to teal #1409

gogonzo opened this issue Nov 13, 2024 · 0 comments
Labels
core question Further information is requested

Comments

@gogonzo
Copy link
Contributor

gogonzo commented Nov 13, 2024

What is your question?

When missing data is passed to the application we need to show the warning somewhere. When data is loaded from teal_data_module, then the warnings about which-dataset-is-missing-for-which-module is displayed in "Data" tab. When one passes a data eagerly, then warning is displayed over tabs. For teal applications wrapped within other applications data can be passed as reactive. In this case "Data" tab is also ommited (as there is no teal_data_module), but otherwise warning is displayed over the tabs (as it needs to be displayed somewhere).

Static or wrapped Dynamic
image image
app with datanames (static)
options(
  teal.log_level = "TRACE",
  teal.show_js_log = TRUE,
  # teal.bs_theme = bslib::bs_theme(version = 5),
  shiny.bookmarkStore = "server"
)

library(bslib)
library(teal)

trans <- list(
  anl_w_datanames = teal_transform_module(
    label = "ANL with datanames",
    datanames = "ADTTE",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer adds ANL based on specified ADSL, ADTTE"),
        numericInput(ns("obs"), "Number of subjects", value = 400, min = 0, max = 400)
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ANL <- dplyr::inner_join(
                head(ADSL, nobs),
                ADTTE[c("STUDYID", "USUBJID", setdiff(colnames(ADTTE), colnames(ADSL)))],
                by = c("USUBJID", "STUDYID")
              )
            },
            nobs = input$obs
          )
        })
      })
    }
  ),
  anl_wout_datanames = teal_transform_module(
    label = "ANL without datanames",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer adds ANL based on unspecified ADSL, ADTTE"),
        numericInput(ns("obs"), "Number of subjects", value = 400, min = 0, max = 400)
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ANL <- dplyr::inner_join(
                head(ADSL, nobs),
                ADTTE[c("STUDYID", "USUBJID", setdiff(colnames(ADTTE), colnames(ADSL)))],
                by = c("USUBJID", "STUDYID")
              )
            },
            nobs = input$obs
          )
        })
      })
    }
  ),
  adsl_w_datanames = teal_transform_module(
    label = "modify ADSL",
    datanames = c("ADSL", "ADTTE"),
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer modifies ADSL based on specified ADTTE")
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ADTTE_summary <- ADTTE |>
                dplyr::group_by(STUDYID, USUBJID) |>
                dplyr::summarize(PARAMCD_AVAL = paste(paste(PARAMCD, "-", AVAL), collapse = "; "))
              ADSL <- dplyr::left_join(ADSL, ADTTE_summary)
            },
            nobs = input$obs
          )
        })
      })
    }
  ),
  adsl_wout_datanames = teal_transform_module(
    label = "modify ADSL",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer modifies ADSL based on unspecified ADTTE")
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ADTTE_summary <- ADTTE |>
                dplyr::group_by(STUDYID, USUBJID) |>
                dplyr::summarize(PARAMCD_AVAL = paste(sprintf("%s - %.2f", PARAMCD, AVAL), collapse = "; "))
              ADSL <- dplyr::left_join(ADSL, ADTTE_summary)
            },
            nobs = input$obs
          )
        })
      })
    }
  )
)

data <- within(data = teal_data(), {
  library(MultiAssayExperiment)
  logger::log_trace("Loading data")
  z <- NULL
  ADSL <- teal.data::rADSL
  ADTTE <- teal.data::rADTTE
  iris <- iris
  `iris raw` <- iris
  `.iris_raw` <- iris
  data.with..dots <- data.frame(letters = letters)
  `1` <- iris
  data("miniACC", package = "MultiAssayExperiment", envir = environment())
  `mini ACC` <- miniACC
  iris <- iris
})
join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")]
data

mods <- modules(
  modules(
    label = "all",
    example_module("all", datanames = "all"),
    example_module("null", datanames = NULL)
  ),
  modules(
    label = "all+set_datanames",
    example_module("all", datanames = "all"),
    example_module("null", datanames = NULL)
  ),
  modules(
    label = "specified",
    example_module("exotic", datanames = c(".iris_raw", "iris raw")),
    example_module("adsl", datanames = "ADSL"),
    example_module("adsl+adtte", datanames = c("ADSL", "ADTTE")),
    example_module("adtte+parent", datanames = "ADTTE")
  ),
  modules(
    label = "transformers",
    example_module("anl - transform w/ datanames", dataname = "ANL", transformers = trans["anl_w_datanames"]),
    example_module("anl - transform w/o datanames", dataname = "ANL", transformers = trans["anl_wout_datanames"]),
    example_module("adsl - transform w/ datanames", dataname = "ADSL", transformers = trans["adsl_w_datanames"]),
    example_module("adsl - transform w/o datanames", dataname = "ADSL", transformers = trans["adsl_wout_datanames"]),
    example_module("all w/o datanames", dataname = "all", transformers = trans["anl_wout_datanames"]),
    example_module("all reset datanames", dataname = "all", transformers = trans["anl_wout_datanames"])
    #  |> set_datanames(c("ADSL", "ADTTE", "ANL"))
  ),
  modules(
    label = "missings",
    example_module("inexisting+existing", datanames = c("ADTTE", "inexisting")),
    example_module("inexisting", datanames = "inexisting")
  ),
  reporter_previewer_module()
)

slices <- teal_slices(
  teal_slice("ADSL", "SEX"),
  teal_slice("ADSL", "AGE", selected = c(18L, 65L)),
  teal_slice("ADTTE", "PARAMCD", selected = "CRSD"),
  include_varnames = list(
    ADSL = c("SEX", "AGE")
  )
)

app <- teal::init(
  data = data,
  modules = mods,
  filter = slices
)

runApp(app)
app with datanames (teal_data_module)
options(
  teal.log_level = "TRACE",
  teal.show_js_log = TRUE,
  # teal.bs_theme = bslib::bs_theme(version = 5),
  shiny.bookmarkStore = "server"
)

library(bslib)
pkgload::load_all("teal.code")
pkgload::load_all("teal.data")
pkgload::load_all("teal")
library(teal)

trans <- list(
  anl_w_datanames = teal_transform_module(
    label = "ANL with datanames",
    datanames = "ADTTE",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer adds ANL based on specified ADSL, ADTTE"),
        numericInput(ns("obs"), "Number of subjects", value = 400, min = 0, max = 400)
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ANL <- dplyr::inner_join(
                head(ADSL, nobs),
                ADTTE[c("STUDYID", "USUBJID", setdiff(colnames(ADTTE), colnames(ADSL)))],
                by = c("USUBJID", "STUDYID")
              )
            },
            nobs = input$obs
          )
        })
      })
    }
  ),
  anl_wout_datanames = teal_transform_module(
    label = "ANL without datanames",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer adds ANL based on unspecified ADSL, ADTTE"),
        numericInput(ns("obs"), "Number of subjects", value = 400, min = 0, max = 400)
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ANL <- dplyr::inner_join(
                head(ADSL, nobs),
                ADTTE[c("STUDYID", "USUBJID", setdiff(colnames(ADTTE), colnames(ADSL)))],
                by = c("USUBJID", "STUDYID")
              )
            },
            nobs = input$obs
          )
        })
      })
    }
  ),
  adsl_w_datanames = teal_transform_module(
    label = "modify ADSL",
    datanames = c("ADSL", "ADTTE"),
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer modifies ADSL based on specified ADTTE")
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ADTTE_summary <- ADTTE |>
                dplyr::group_by(STUDYID, USUBJID) |>
                dplyr::summarize(PARAMCD_AVAL = paste(paste(PARAMCD, "-", AVAL), collapse = "; "))
              ADSL <- dplyr::left_join(ADSL, ADTTE_summary)
            },
            nobs = input$obs
          )
        })
      })
    }
  ),
  adsl_wout_datanames = teal_transform_module(
    label = "modify ADSL",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer modifies ADSL based on unspecified ADTTE")
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(),
            {
              ADTTE_summary <- ADTTE |>
                dplyr::group_by(STUDYID, USUBJID) |>
                dplyr::summarize(PARAMCD_AVAL = paste(sprintf("%s - %.2f", PARAMCD, AVAL), collapse = "; "))
              ADSL <- dplyr::left_join(ADSL, ADTTE_summary)
            },
            nobs = input$obs
          )
        })
      })
    }
  )
)

data <- teal_data_module(
  once = FALSE,
  ui = function(id) {
    ns <- NS(id)
    tagList(
      numericInput(ns("obs"), "Number of observations to show", 1000),
      actionButton(ns("submit"), label = "Submit")
    )
  },
  server = function(id, ...) {
    moduleServer(id, function(input, output, session) {
      logger::log_trace("example_module_transform2 initializing.")
      eventReactive(input$submit, {
        data <- within(data = teal_data(), n = as.numeric(input$obs), {
          library(MultiAssayExperiment)
          logger::log_trace("Loading data")
          z <- NULL
          ADSL <- head(teal.data::rADSL, n = n)
          ADTTE <- teal.data::rADTTE
          iris <- iris
          `iris raw` <- iris
          `.iris_raw` <- iris
          data.with..dots <- data.frame(letters = letters)
          `1` <- iris
          data("miniACC", package = "MultiAssayExperiment", envir = environment())
          `mini ACC` <- miniACC
          iris <- iris
        })
        join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")]
        data
      })
    })
  }
)

mods <- modules(
  modules(
    label = "all",
    example_module("all", datanames = "all"),
    example_module("null", datanames = NULL)
  ),
  modules(
    label = "all+set_datanames",
    example_module("all", datanames = "all"),
    example_module("null", datanames = NULL)
  ),
  modules(
    label = "specified",
    example_module("exotic", datanames = c(".iris_raw", "iris raw")),
    example_module("adsl", datanames = "ADSL"),
    example_module("adsl+adtte", datanames = c("ADSL", "ADTTE")),
    example_module("adtte+parent", datanames = "ADTTE")
  ),
  modules(
    label = "transforms",
    example_module("anl - transform w/ datanames", dataname = "ANL", transforms = trans["anl_w_datanames"]),
    example_module("anl - transform w/o datanames", dataname = "ANL", transforms = trans["anl_wout_datanames"]),
    example_module("adsl - transform w/ datanames", dataname = "ADSL", transforms = trans["adsl_w_datanames"]),
    example_module("adsl - transform w/o datanames", dataname = "ADSL", transforms = trans["adsl_wout_datanames"]),
    example_module("all w/o datanames", dataname = "all", transforms = trans["anl_wout_datanames"]),
    example_module("all reset datanames", dataname = "all", transforms = trans["anl_wout_datanames"])
    #  |> set_datanames(c("ADSL", "ADTTE", "ANL"))
  ),
  modules(
    label = "missings",
    example_module("inexisting+existing", datanames = c("ADTTE", "inexisting")),
    example_module("inexisting", datanames = "inexisting")
  ),
  reporter_previewer_module()
)

slices <- teal_slices(
  teal_slice("ADSL", "SEX"),
  teal_slice("ADSL", "AGE", selected = c(18L, 65L)),
  teal_slice("ADTTE", "PARAMCD", selected = "CRSD"),
  include_varnames = list(
    ADSL = c("SEX", "AGE")
  )
)

app <- teal::init(
  data = data,
  modules = mods,
  filter = slices
)

runApp(app)
@gogonzo gogonzo added question Further information is requested core labels Nov 13, 2024
gogonzo added a commit that referenced this issue Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant