-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Handle validation in d-e-s #113
Conversation
A couple of questions. I think I know 1. and 2. because of insightsengineering/teal.osprey/pull/199 but just want to double check.
|
They can be yes - it's up to what the module developer chooses to do with these messages
Correct - the only places d-e-s are used are tmg and tmc so the following issues would then make use of this functionality: |
Hi All, I don't think that validation of the filters are urgent right now. I have an opinion that we can remove data_extract in the future or simplify this to the form which can be:
@mhallal1 if you conclude that validation of the d-e-s filter is too complicated please just skip this. Validating select still makes sense. |
Adds input validation for `filter_spec` similar to `select_spec`. One thing I want to note is that within `data_extract_read_srv` is the variable [`filter_idx`](https://github.com/insightsengineering/teal.transform/blob/7b0e91ef4cafa856fd5b496c60b02d17b42fe96f/R/data_extract_read_module.R#L23) which presumably can have length > 1. Because it can have length > 1, I would think we need to have multiple `iv$add_rule` calls, 1 for each element of `filter_idx`. However, it seems to be working with a [single call](https://github.com/insightsengineering/teal.transform/blob/7b0e91ef4cafa856fd5b496c60b02d17b42fe96f/R/data_extract_read_module.R#L78). I'm thinking I'm misunderstanding how to create a `filter_spec` that would result in `length(filter_idx) > 1`. It would be great if some can test this out. My attempt was the following ``` library(shiny) library(teal.transform) library(shinyvalidate) ADSL <- data.frame( STUDYID = c("B", rep(c("A", "B", "B"), 3)), USUBJID = LETTERS[1:10], SEX = rep(c("F", "M"), 5), AGE = rpois(10, 30), BMRKR1 = rlnorm(10) ) adsl_extract <- data_extract_spec( dataname = "ADSL", filter = filter_spec( vars = c("SEX", "STUDYID"), choices = c("F - A", "M - A", "F - B", "M - B"), selected = c("F - A") ), select = select_spec( label = "Select variable:", choices = variable_choices(ADSL, c("AGE", "BMRKR1")), selected = "AGE", multiple = TRUE, fixed = FALSE ) ) mtcars_extract <- data_extract_spec( dataname = "mtcars", filter = filter_spec( vars = c("cyl", "am"), choices = c("4 - 1", "8 - 1", "4 - 0"), sep = " - ", multiple = TRUE ), select = select_spec( label = "Select variable: ", choices = variable_choices(mtcars, c("mpg", "hp")), multiple = TRUE ) ) data_list <- list(ADSL = reactive(ADSL), mtcars = reactive(mtcars)) join_keys <- teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) app <- shinyApp( ui = fluidPage( shinyjs::useShinyjs(), teal.widgets::standard_layout( output = verbatimTextOutput("out1"), encoding = tagList( data_extract_ui( id = "des_var", label = "Selection", data_extract_spec = list(adsl_extract, mtcars_extract) ) ) ) ), server = function(input, output, session) { des_reactive_input <- data_extract_srv( id = "des_var", datasets = data_list, data_extract_spec = list(adsl_extract, mtcars_extract), join_keys = join_keys, select_validation_rule = sv_required(message = "Please please select a column from a dataset"), filter_validation_rule = sv_required(message = "filter test") #optional add this to add a nice message #dataset_validation_rule = sv_required(message = "Please select a dataset!") ) iv_r <- reactive({ iv <- InputValidator$new() des_reactive_input()$iv$enable() iv$add_validator(des_reactive_input()$iv) iv$enable() iv iv }) output$out1 <- renderPrint({ if (iv_r()$is_valid()) des_reactive_input() else "Check that you have made a selection" }) } ) runApp(app) ``` Signed-off-by: Mahmoud Hallal <86970066+mhallal1@users.noreply.github.com> Co-authored-by: Mahmoud Hallal <mahmoud.hallal@roche.com> Co-authored-by: Mahmoud Hallal <86970066+mhallal1@users.noreply.github.com> Co-authored-by: Nikolas Burkoff <nikolas.burkoff@roche.com>
After reading the vignette in shinyvalidate I no longer think it's weird or too complicated. It adds the complexity to the data_extract but doesn't change the default functionality which remains the same.
|
So I agree with the above @gogonzo except:
This would then require data_merge output to include |
Yup, let's not add iv to the output of data_merge. Yes, this would require splitting merge_expression_module to data_extract_multiple_srv and merge_expression_srv everywhere we want inputs to be validated. |
So how do I add a conditional validation rule? EDIT: To clarify, normally I would do
|
There are two ways to do it - if you need reactivity put the condition inside the rule (write your own ~ if () or function(value) rule), if you don't then you can create the selection_validation_rule list with the rule there or not |
Will |
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@capgemini.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through the code and everything looks good. I've tried to break the modules but didn't "succeed". Extra exported function still bothers me but I guess we have no choice as we need to include iv
from multiple extracts into parent iv
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…teal.transform into validator_test@main
Code Coverage Summary
Diff against main
Results for commit: 3b8d9a3 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
This would close #112
See examples in the issue
Tests for new functionality still required