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

Filter fix #119

Merged
merged 9 commits into from
Jan 3, 2023
Merged

Filter fix #119

merged 9 commits into from
Jan 3, 2023

Conversation

mhallal1
Copy link
Contributor

closes #117

The two updateOptionalSelectInput could not be removed because of their need when the selection is not assigned by default, check tm_g_distribution example app from tmg for clarification.

We now account for when something is pre-selected in data_extract_filter_srv and assign the selected value to it.
Test with app below and try to remove the selected value also:
Also test with modules from tmg and tmc.

library(shiny)

extract_ui <- function(id, data_extract) {
  ns <- NS(id)
  teal.widgets::standard_layout(
    output = teal.widgets::white_small_well(verbatimTextOutput(ns("output"))),
    encoding = data_extract_ui(ns("data_extract"), label = "variable", data_extract)
  )
}

extract_srv <- function(id, data, data_extract) {
  moduleServer(id, function(input, output, session) {
    reactive_extract_input <- data_extract_srv("data_extract", data, data_extract, join_keys = attr(data, "join_keys"))

    merged <- merge_expression_srv(selector_list = reactive(list(x = reactive_extract_input)), datasets = data, join_keys = attr(data, "join_keys"))
    s <- reactive(merged()$expr)
    output$output <- renderPrint(s())
  })
}

tm_extract <- function(label = "extract", data_extract) {
  teal::module(
    label = label,
    server = extract_srv,
    ui = extract_ui,
    server_args = list(data_extract = data_extract),
    ui_args = list(data_extract = data_extract)
  )
}

# Define data.frame objects
ADSL <- scda::synthetic_cdisc_data("latest")$adsl # nolint
ADTTE <- scda::synthetic_cdisc_data("latest")$adtte # nolint

# create a list of data.frame objects
data <- cdisc_data(
  cdisc_dataset("ADSL", ADSL),
  cdisc_dataset("ADTTE", ADTTE)
)

app <- teal::init(
  data = data,
  modules = list(
    tm_extract(
      "extract-4",
      data_extract_spec(
        dataname = "ADTTE",
        filter = filter_spec(
          vars = "PARAMCD",
          value_choices(ADTTE, "PARAMCD", "PARAM"), 
          selected = "OS"
        )
      )
    )
  )
)

runApp(app)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 28, 2022

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  --------------------------------------------------------------------
R/all_choices.R                       1       0  100.00%
R/call_utils.R                      156     124  20.51%   14-23, 64, 66, 68, 107-431
R/check_selector.R                   31       0  100.00%
R/choices_labeled.R                 200      61  69.50%   60, 66, 71, 78, 94, 218-222, 226-231, 261-274, 388-389, 391, 423-471
R/choices_selected.R                 81      11  86.42%   201-229, 260
R/column_functions.R                  3       3  0.00%    13-16
R/data_extract_datanames.R           32       8  75.00%   9-13, 64-66
R/data_extract_filter_module.R       95      16  83.16%   75-88, 90-91, 145
R/data_extract_module.R             247      61  75.30%   3, 121, 126, 143, 146-151, 153, 172-175, 203-249, 446, 451, 482, 585
R/data_extract_read_module.R        123      13  89.43%   28, 32-35, 103-108, 117, 134
R/data_extract_select_module.R       32      18  43.75%   31-48
R/data_extract_single_module.R       53       2  96.23%   29, 42
R/data_extract_spec.R                32       0  100.00%
R/data_merge_module.R                58      15  74.14%   101-118
R/filter_spec.R                     186       1  99.46%   373
R/format_data_extract.R              16       1  93.75%   49
R/get_dplyr_call.R                  299       0  100.00%
R/get_merge_call.R                  280      29  89.64%   28-34, 45, 206-215, 368, 384-396
R/include_css_js.R                    5       0  100.00%
R/input_checks.R                     11       2  81.82%   18-19
R/merge_data_utils.R                  2       0  100.00%
R/merge_datasets.R                  135       6  95.56%   77, 225-229
R/merge_expression_module.R          46       1  97.83%   147
R/resolve_delayed.R                  16       0  100.00%
R/resolve.R                         114      44  61.40%   229-312
R/select_spec.R                      49       8  83.67%   149, 213-220
R/utils.R                            15      11  26.67%   26-39
R/zzz.R                               2       2  0.00%    2-3
TOTAL                              2320     437  81.16%

Diff against main

Filename                          Stmts    Miss  Cover
------------------------------  -------  ------  -------
R/data_extract_filter_module.R       +3      +5  -4.89%
TOTAL                                +3      +5  -0.19%

Results for commit: c761af6

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@mhallal1 mhallal1 changed the title 117 filter fix@main Filter fix Dec 28, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 28, 2022

Unit Tests Summary

    1 files    24 suites   39s ⏱️
193 tests 192 ✔️ 1 💤 0
669 runs  668 ✔️ 1 💤 0

Results for commit 5a8fe36.

♻️ This comment has been updated with latest results.

@mhallal1 mhallal1 added the core label Dec 29, 2022
@@ -60,4 +60,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Comment on lines 81 to 88
selected <- if (!is.null(filter$selected)) {
filter$selected
} else {
selected <- choices[1]
if (filter$multiple) {
choices
} else {
choices[1]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God, the ifs xd

Comment on lines 84 to 88
if (filter$multiple) {
choices
} else {
choices[1]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the type of choices in here? Is it possible to abuse this R thing:

val = 2
print(val[1])
# prints 2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly enough, I have a vague recollection of asking myself this question in these parts of the code in the past xd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested choices with AGE and SEX which returned the types integer and character respectively.

Copy link
Contributor

@asbates asbates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like issue is resolved to me. There may be another issue but it's not directly related to #117 so I opened #120.

Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gogonzo gogonzo enabled auto-merge (squash) January 2, 2023 14:58
@gogonzo gogonzo merged commit 21d450a into main Jan 3, 2023
@gogonzo gogonzo deleted the 117_filter_fix@main branch January 3, 2023 10:29
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.

Odd data_extract_spec behaviour
4 participants