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

Refactor of the filter panel #851

Merged
merged 26 commits into from
Jul 14, 2023
Merged

Refactor of the filter panel #851

merged 26 commits into from
Jul 14, 2023

Conversation

gogonzo
Copy link
Contributor

@gogonzo gogonzo commented Jun 16, 2023

To observe checks

gogonzo and others added 10 commits March 9, 2023 15:25
Introduces changes necessary to handle the new Filter Panel API coming
from [this
PR](insightsengineering/teal.slice#222).

---------

Co-authored-by: Dawid Kałędkowski <[email protected]>
Co-authored-by: Andrew Bates <[email protected]>
Co-authored-by: asbates <[email protected]>
Co-authored-by: chlebowa <[email protected]>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
The follow-up after
insightsengineering/coredev-tasks#235

The current spelling-check output is below. `omics` is a part of
`multi-omics`. `pre-selected` is treated as spelling mistake either if
it's written `pre-selected` or `preselected`. `themer` and `theming` are
a part of subject-language about themes. `tabsetted` does not seem to be
an English word, even though TabSet class became of common word around
developers.

```{R}
spelling::spell_check_package()
  WORD               FOUND IN
Forkers            README.md:75,85,87
funder             teal-package.Rd:32
Hoffmann           teal-package.Rd:32
omics              README.md:29
                   including-mae-data-in-teal.Rmd:13
preselected        teal.Rmd:101
programmatically   NEWS.md:118
repo               README.md:9,15,83,87
reproducibility    init.Rd:24,25
                   srv_teal_with_splash.Rd:23,24
                   ui_teal_with_splash.Rd:25,26
                   NEWS.md:71,91,282
                   README.md:44
                   adding-support-for-reporting.Rmd:238
                   including-adam-data-in-teal.Rmd:16,104
                   including-general-data-in-teal.Rmd:80
                   including-mae-data-in-teal.Rmd:41
                   preprocessing-data.Rmd:87
                   teal.Rmd:75
tabsetted          ui_teal.Rd:43
themer             teal-bs-themes.Rmd:188,222
theming            teal-bs-themes.Rmd:39,108
TLG                README.md:53
UI                 init.Rd:5
                   srv_teal.Rd:103
                   ui_nested_tabs.Rd:8,35,42
                   ui_tabs_with_filters.Rd:25
                   ui_teal.Rd:5,19,20,35,38,41,43,46
                   ui_teal_with_splash.Rd:5
                   NEWS.md:118,194,210,313,317,366
                   creating-custom-modules.Rmd:47,49,52
                   teal-options.Rmd:89
                   teal.Rmd:59
UIs                ui_tabs_with_filters.Rd:5
uncheck            teal-bs-themes.Rmd:175
UX                 teal-options.Rmd:89

```
@github-actions
Copy link
Contributor

github-actions bot commented Jun 16, 2023

badge

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  ------------------------------------------------------
R/dummy_functions.R                 74      61  17.57%   12-95
R/example_module.R                  18       9  50.00%   23-26, 29-33
R/get_rcode_utils.R                 46       1  97.83%   49
R/include_css_js.R                  24       0  100.00%
R/init.R                            76      12  84.21%   147-148, 192-201, 213-215
R/module_filter_manager.R          127      60  52.76%   3-75, 148, 177-182, 197-204, 208-220, 224-227, 231-234
R/module_nested_tabs.R             171      16  90.64%   59, 108, 112-113, 127-134, 162, 214, 236, 269
R/module_tabs_with_filters.R        70       8  88.57%   132-138, 160, 181
R/module_teal_with_splash.R         33       2  93.94%   65, 77
R/module_teal.R                    154       7  95.45%   49, 52, 155-156, 204-205, 227
R/modules_debugging.R               18      18  0.00%    37-56
R/modules.R                        106       8  92.45%   351-376
R/reporter_previewer_module.R       12       2  83.33%   18, 22
R/show_rcode_modal.R                20      20  0.00%    16-37
R/tdata.R                           41       2  95.12%   146, 172
R/teal_slices.R                     43       0  100.00%
R/utils.R                           21       8  61.90%   38-47
R/validate_inputs.R                 32       0  100.00%
R/validations.R                     62      39  37.10%   107-368
R/zzz.R                             11       7  36.36%   3-14
TOTAL                             1159     280  75.84%

Diff against main

Filename                        Stmts    Miss  Cover
----------------------------  -------  ------  --------
R/get_rcode_utils.R                -7      -1  +1.60%
R/init.R                          +52     +10  -7.46%
R/module_filter_manager.R        +127     +60  +52.76%
R/module_nested_tabs.R            +10      +9  -5.01%
R/module_tabs_with_filters.R       +2      +7  -9.96%
R/module_teal.R                   +43      +2  -0.04%
R/modules.R                        +5       0  +0.37%
R/teal_slices.R                   +43       0  +100.00%
R/utils.R                          +8      +8  -38.10%
TOTAL                            +283     +95  -0.57%

Results for commit: e3b3a42

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

kartikeyakirar and others added 5 commits June 21, 2023 18:09
this fixes insightsengineering/teal.slice#330

Here in this PR , parameter module_add is being added to
teal::teal_filters() which passes parameter value to
teal.slice::filter_settings() function.

Testing code:
```
options(teal.log_level = "TRACE", teal.show_js_log = TRUE)
# options("teal.bs_theme" = bslib::bs_theme(version = 5))
# options(shiny.trace = TRUE)
# todo: change groupCheckbox to include locked (not able to interact with)
#       change groupCheckbox to have some colors (instead of grey)
# todo: available filter should present information about selected values (for example tooltip)


library(shiny)
library(scda)
library(scda.2022)
library(teal.data)
library(teal.transform)
library(teal.modules.general)
pkgload::load_all()

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")()
      })
    }
  )
}

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$categorical2 <- sample(letters[1:10], size = nrow(ADSL), replace = TRUE)
ADSL$categorical <- 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$categorical2[sample(1:nrow(ADSL), size = 10)] <- NA
ADSL$categorical[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 <- teal::teal_filters(
  filter_var(dataname = "ADSL", varname = "categorical", selected = c("a", "b"), id = "categorical", locked = TRUE),
  filter_var(dataname = "ADSL", varname = "categorical2", selected = c("a", "b"), locked = TRUE),
  filter_var(dataname = "ADSL", varname = "numeric", selected = c(0, 140), keep_na = TRUE, keep_inf = TRUE),
  filter_var(dataname = "ADSL", varname = "logical", selected = c(T), keep_na = TRUE, keep_inf = TRUE),
  filter_var(dataname = "ADSL", varname = "datetime"),
  filter_var(dataname = "ADSL", varname = "date2"),
  filter_expr(id = "AF", title = "ADULT FEMALE", dataname = "ADSL", expr = "SEX %in% 'F' & AGE >= 18L"),
  filter_expr(id = "SE", title = "Safety-Evaluable", dataname = "ADSL", expr = "SAFFL == 'Y'"),
  filter_var(dataname = "ADSL", varname = "COUNTRY", selected = c("USA", "CAN", "JPN"), fixed = TRUE),
  count_type = "all",
  include_varnames = list(ADSL = c("SEX", "categorical", "categorical2", "numeric", "logical", "date", "datetime", "date2", "datetime2", "COUNTRY")),
  exclude_varnames = list(
    ADTTE = intersect(colnames(ADSL), colnames(ADTTE)),
    ADRS = colnames(ADSL)
  ),
  mapping = list(
    `table` = "categorical"
  ),
  module_specific = TRUE,
  module_add = FALSE  # set it to true for seeing filter add module

)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", ADSL),
    cdisc_dataset("ADTTE", ADTTE),
    cdisc_dataset("ADRS", ADRS)
  ),
  modules = modules(
    tm_data_table(
      "table",
      variables_selected = list(ADSL = c("STUDYID", "USUBJID", "SUBJID", "SITEID", "AGE", "SEX")),
      dt_args = list(caption = "ADSL Table Caption")
    ),
    modules(
      label = "tab1",
      funny_module("funny", datanames = NULL),
      funny_module("funny2", datanames = "ADTTE") # will limit datanames to ADTTE and ADSL (parent)
    )
  ),
  filter = default_filters
)


runApp(app)
```

Co-authored-by: kartikeya <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Jun 29, 2023

Unit Tests Summary

    1 files    14 suites   16s ⏱️
156 tests 156 ✔️ 0 💤 0
313 runs  313 ✔️ 0 💤 0

Results for commit 0a3f7f0.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 12, 2023

badge

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  -------------------------------------------------------
R/dummy_functions.R                 88      75  14.77%   12-110
R/example_module.R                  18       9  50.00%   23-26, 29-33
R/get_rcode_utils.R                 46       1  97.83%   49
R/include_css_js.R                  24       0  100.00%
R/init.R                            76      12  84.21%   150-151, 195-204, 216-218
R/module_filter_manager.R          127      60  52.76%   47-79, 152, 181-186, 201-208, 212-224, 228-231, 235-238
R/module_nested_tabs.R             171      16  90.64%   59, 108, 112-113, 127-134, 162, 214, 236, 269
R/module_tabs_with_filters.R        70       8  88.57%   132-138, 160, 181
R/module_teal_with_splash.R         33       2  93.94%   65, 77
R/module_teal.R                    163      12  92.64%   49, 52, 155-156, 204-205, 225-228, 230, 234
R/modules_debugging.R               18      18  0.00%    25-44
R/modules.R                        108       8  92.59%   332-357
R/reporter_previewer_module.R       16       2  87.50%   23, 27
R/show_rcode_modal.R                20      20  0.00%    16-37
R/tdata.R                           41       2  95.12%   146, 172
R/teal_slices.R                     43       0  100.00%
R/utils.R                           21       8  61.90%   38-47
R/validate_inputs.R                 32       0  100.00%
R/validations.R                     62      39  37.10%   111-375
R/zzz.R                             11       7  36.36%   3-14
TOTAL                             1188     299  74.83%

Diff against main

Filename                        Stmts    Miss  Cover
----------------------------  -------  ------  --------
R/get_rcode_utils.R                -7      -1  +1.60%
R/init.R                          +52     +10  -7.46%
R/module_filter_manager.R        +127     +60  +52.76%
R/module_nested_tabs.R            +10      +9  -5.01%
R/module_tabs_with_filters.R       +2      +7  -9.96%
R/module_teal.R                   +43      +2  +0.97%
R/modules.R                        +7       0  +0.51%
R/teal_slices.R                   +43       0  +100.00%
R/utils.R                          +8      +8  -38.10%
TOTAL                            +285     +95  -0.36%

Results for commit: 803994b

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@gogonzo gogonzo added the core label Jul 12, 2023
Part of insightsengineering/teal.slice#52

---------

Co-authored-by: Aleksander Chlebowski <[email protected]>
@gogonzo gogonzo merged commit 4bd3d4d into main Jul 14, 2023
22 checks passed
@gogonzo gogonzo deleted the filter_panel_refactor@main branch July 14, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants