insightsengineering / teal.slice

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

choices counts issue in filter panel #578

Closed gogonzo closed 3 months ago

gogonzo commented 3 months ago

Closes #579

Fix a bug after #576 - in previous PR I've changed accidentaly order of choices to be dependent on a data and not on the factor levels. Which led to the situation in the exploratory app that SEX choices was M, F while its counts was F, M. You can test it by:

image

This PR fixes the problem as both counts and choices are set by the same value.

github-actions[bot] commented 3 months ago

Unit Tests Summary

  1 files   29 suites   25s :stopwatch: 359 tests 359 :white_check_mark: 0 :zzz: 0 :x: 825 runs  825 :white_check_mark: 0 :zzz: 0 :x:

Results for commit 58b3cd58.

:recycle: This comment has been updated with latest results.

m7pr commented 3 months ago

@gogonzo two tests are failing

gogonzo commented 3 months ago

Limited choices caused failure on counts - reproducible also in the release version. This PR fixes this

options(teal.log_level = "TRACE", teal.show_js_log = TRUE)
library(teal)
library(shiny)
library(scda)

ADSL <- synthetic_cdisc_data("latest")$adsl
ADSL$empty <- NA
ADSL$numeric_categorical <- sample(1:3, size = nrow(ADSL), replace = TRUE)
ADSL$categorical <- sample(letters[1:10], size = nrow(ADSL), replace = TRUE)
ADSL$ordered <- ordered(sample(letters[1:10], size = nrow(ADSL), replace = TRUE))
ADSL$date_categorical <- sample(Sys.Date() + 1:4, size = nrow(ADSL), replace = TRUE)
ADSL$datetime_categorical <- sample(Sys.time() + (1:4) * 3600, size = nrow(ADSL), replace = TRUE)

ADSL$numeric_categorical[sample(1:nrow(ADSL), size = 10, )] <- NA
ADSL$date_categorical[sample(1:nrow(ADSL), size = 10, )] <- NA
ADSL$datetime_categorical[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

pkgload::load_all("teal.slice")
app <- init(
  data = teal_data(ADSL = ADSL, ADTTE = ADTTE, ADRS = ADRS),
  modules = list(example_module()),
  filter = teal_slices(
    teal_slice("ADSL", "empty"),
    teal_slice("ADSL", "numeric_categorical", choices = unique(ADSL$numeric_categorical)[1:2]),
    teal_slice("ADSL", "categorical", choices = unique(ADSL$categorical)[1:2]),
    teal_slice("ADSL", "ordered", choices = unique(ADSL$ordered)[1:2]),
    teal_slice("ADSL", "date_categorical", choices = unique(ADSL$date_categorical)[1:2]),
    teal_slice("ADSL", "datetime_categorical", choices = unique(ADSL$datetime_categorical)[1:2]),
    count_type = "all"
  )
)

runApp(app)

image

github-actions[bot] commented 3 months ago

badge

Code Coverage Summary

Filename                        Stmts    Miss  Cover    Missing
----------------------------  -------  ------  -------  ------------------------------------------------------------------------------------------------------------------------------------------------------
R/calls_combine_by.R                7       0  100.00%
R/choices_labeled.R                49      14  71.43%   25, 36, 41, 51-56, 68, 72-76
R/count_labels.R                   97       0  100.00%
R/filter_panel_api.R               29       1  96.55%   132
R/FilteredData-utils.R             68      25  63.24%   21-24, 27-30, 52-57, 153, 175-184
R/FilteredData.R                  562     227  59.61%   110, 184, 326, 398, 501-510, 533, 554-595, 613-616, 632, 673-706, 721-723, 727-733, 762-790, 813-815, 819-821, 824-838, 842-852, 855-898, 939, 962-984
R/FilteredDataset-utils.R          23       1  95.65%   125
R/FilteredDataset.R               170      61  64.12%   52, 152, 191, 216-273, 312-314
R/FilteredDatasetDataframe.R      121       8  93.39%   87, 148, 158, 234-238
R/FilteredDatasetDefault.R         18       4  77.78%   103-116
R/FilteredDatasetMAE.R            134      37  72.39%   56, 117-122, 161-166, 170-171, 189-211
R/FilterPanelAPI.R                 10       0  100.00%
R/FilterState-utils.R             101       2  98.02%   264, 294
R/FilterState.R                   361      61  83.10%   89, 212, 230-234, 241-242, 256-257, 263-264, 311, 313, 315, 367, 411, 639, 682-705, 715-734, 769-775, 784-790
R/FilterStateChoices.R            342     111  67.54%   296, 338-340, 362-369, 373-390, 418-420, 433-444, 456-464, 468-497, 518-521, 524-527, 538-563, 574, 579, 590
R/FilterStateDate.R               215     129  40.00%   230, 282-439
R/FilterStateDatettime.R          309     199  35.60%   266, 318-549
R/FilterStateEmpty.R               53      31  41.51%   89, 99-104, 117, 129-169
R/FilterStateExpr.R                75      62  17.33%   149-272
R/FilterStateLogical.R            196     144  26.53%   136, 158, 218, 222-406
R/FilterStateRange.R              408     105  74.26%   262, 384, 510-514, 517-527, 530, 542-548, 559-571, 575-585, 589-591, 605-632, 647, 650, 664-681, 716-721, 731-733
R/FilterStates-utils.R             70       9  87.14%   108, 127, 188-194, 216, 245
R/FilterStates.R                  364      30  91.76%   78-82, 191, 314-323, 411-414, 457, 542-546, 591, 712-715
R/FilterStatesDF.R                  5       0  100.00%
R/FilterStatesMAE.R                10       1  90.00%   40
R/FilterStatesMatrix.R              3       0  100.00%
R/FilterStatesSE.R                211     157  25.59%   36, 71-73, 83-85, 109-116, 124-131, 154-302
R/include_css_js.R                  5       5  0.00%    12-16
R/teal_slice.R                    107       4  96.26%   131, 195-196, 206
R/teal_slices.R                    84       5  94.05%   150-155
R/test_utils.R                     21       0  100.00%
R/utils.R                          18       0  100.00%
R/variable_types.R                 15       8  46.67%   44-51
R/zzz.R                            17      17  0.00%    3-47
TOTAL                            4278    1458  65.92%

Diff against main

Filename                  Stmts    Miss  Cover
----------------------  -------  ------  -------
R/FilterStateChoices.R      +10      +3  +0.07%
TOTAL                       +10      +3  +0.01%

Results for commit: 58b3cd5838262cc05de2d18e98b3ea7b3456fe76

Minimum allowed coverage is 80%

:recycle: This comment has been updated with latest results

github-actions[bot] commented 3 months ago

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
FilteredData 💔 $9.83$ $+1.06$ $0$ $0$ $0$ $0$

Results for commit 8027fdb6da7171559155e50a7540060f2bb3dd0c

♻️ This comment has been updated with latest results.