insightsengineering / teal.slice

Reproducible slice module for teal applications
https://insightsengineering.github.io/teal.slice/
Other
11 stars 5 forks source link

If initializing a filter card as disabled, inputs should be disabled #241

Closed asbates closed 1 year ago

asbates commented 1 year ago

This may end up being resolved with some branch merges, but if not:

When initializing a filter card as disabled, inputs are not disabled. But inputs should be disabled.

donyunardi commented 1 year ago

Acceptance Criteria:

gogonzo commented 1 year ago

This have been addressed in #265 .

See the example where categorical2 is disabled filter_var(dataname = "ADSL", varname = "categorical2", selected = c("a", "b"), fixed = TRUE, disabled = TRUE),

funny_module <- function (label = "Filter states", datanames = "all") {
  checkmate::assert_string(label)
  module(
    label = label,
    filters = datanames,
    ui = function(id, ...) {
      ns <- NS(id)
      div(
        h2("The following filter calls are generated:"),
        verbatimTextOutput(ns("filter_states")),
        verbatimTextOutput(ns("filter_calls")),
        actionButton(ns("reset"), "reset_to_default")
      )
    },
    server = function(input, output, session, data, filter_panel_api) {
      checkmate::assert_class(data, "tdata")
      observeEvent(input$reset, set_filter_state(filter_panel_api, default_filters))
      output$filter_states <-  renderPrint({
        logger::log_trace("rendering text1")
        filter_panel_api |> get_filter_state()
      })
      output$filter_calls <- renderText({
        logger::log_trace("rendering text2")
        attr(data, "code")()
      })
    }
  )
}

#options(teal.log_level = "TRACE", teal.show_js_log = TRUE)
options("teal.bs_theme" = bslib::bs_theme(version = 5))
#options(shiny.trace = TRUE)
pkgload::load_all("teal.slice")
pkgload::load_all("teal")
library(scda)

ADSL <- synthetic_cdisc_data("latest")$adsl
ADSL$empty <- NA
ADSL$logical1 <- FALSE
ADSL$logical <- sample(c(TRUE, FALSE), size = nrow(ADSL), replace = TRUE)
ADSL$numeric <- rnorm(nrow(ADSL))
ADSL$categorical <- sample(letters[1:10], size = nrow(ADSL), replace = TRUE)
ADSL$categorical2 <- sample(letters[1:3], size = nrow(ADSL), replace = TRUE, prob = c(.1, .3, .6))
ADSL$date <- Sys.Date() + seq_len(nrow(ADSL))
ADSL$date2 <- rep(Sys.Date() + 1:3, length.out = nrow(ADSL))
ADSL$datetime <- Sys.time() + seq_len(nrow(ADSL)) * 3600 * 12
ADSL$datetime2 <- rep(Sys.time() + 1:3 * 43200, length.out = nrow(ADSL))

ADSL$numeric[sample(1:nrow(ADSL), size = 10)] <- NA
ADSL$numeric[sample(1:nrow(ADSL), size = 10)] <- Inf
ADSL$logical[sample(1:nrow(ADSL), size = 10)] <- NA
ADSL$date[sample(1:nrow(ADSL), size = 10)] <- NA
ADSL$datetime[sample(1:nrow(ADSL), size = 10)] <- NA
ADSL$categorical[sample(1:nrow(ADSL), size = 10)] <- NA
ADSL$categorical2[sample(1:nrow(ADSL), size = 10)] <- NA

ADTTE <- synthetic_cdisc_data("latest")$adtte
ADRS <- synthetic_cdisc_data("latest")$adrs

ADTTE$numeric <- rnorm(nrow(ADTTE))
ADTTE$numeric[sample(1:nrow(ADTTE), size = 10,)] <- NA

default_filters <- filter_settings(
  filter_expr(id = "AD", title = "ADULTS", dataname = "ADSL", expr = quote(SEX %in% c("F", "M") & AGE >= 18L)),
  filter_var(dataname = "ADSL", varname = "categorical2", selected = c("a", "b"), fixed = TRUE, disabled = TRUE),
  filter_var(dataname = "ADSL", varname = "numeric", selected = c(0, 140), keep_na = TRUE, keep_inf = TRUE, fixed = TRUE),
  filter_var(dataname = "ADSL", varname = "SEX", fixed = FALSE),
  filter_var(dataname = "ADSL", varname = "logical", selected = FALSE, fixed = TRUE),
  filter_var(dataname = "ADSL", varname = "date", selected = c(Sys.Date() + 5, "2050-10-12"), fixed = TRUE),
  filter_var(dataname = "ADSL", varname = "datetime", fixed = TRUE),
  filter_var(dataname = "ADSL", varname = "date2", fixed = TRUE),
  filter_var(dataname = "ADSL", varname = "datetime2", fixed = TRUE),
  filter_var(dataname = "ADTTE", varname = "AVAL", selected = c(10, 1000), keep_na = TRUE, keep_inf = TRUE, fixed = TRUE),
  count_type = "all",
  include_varnames = list(ADSL = c("SEX", "categorical2", "numeric", "logical", "date", "datetime", "date2", "datetime2")),
  exclude_varnames = list(
    ADTTE = intersect(colnames(ADSL), colnames(ADTTE)),
    ADRS = colnames(ADSL)
  )
)

data <- cdisc_data(
  cdisc_dataset("ADSL", ADSL),
  cdisc_dataset("ADTTE", ADTTE),
  cdisc_dataset("ADRS", ADRS)
)

app <- init(
  data = data,
  modules = list(funny_module(), funny_module("module2")),
  filter = default_filters
)

runApp(app)