From d80b6b8d2fd4b939a857568b7ef5ae76bd83ad74 Mon Sep 17 00:00:00 2001 From: Nikolas Burkoff Date: Tue, 6 Dec 2022 14:09:05 +0000 Subject: [PATCH] tm_t_events --- R/tm_t_events.R | 55 +++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/R/tm_t_events.R b/R/tm_t_events.R index 0773addc0a..d0b7ff67ed 100644 --- a/R/tm_t_events.R +++ b/R/tm_t_events.R @@ -639,11 +639,40 @@ srv_t_events_byterm <- function(id, checkmate::assert_class(data, "tdata") shiny::moduleServer(id, function(input, output, session) { - anl_inputs <- teal.transform::merge_expression_module( - datasets = data, + + selector_list <- teal.transform::data_extract_multiple_srv( data_extract = list(arm_var = arm_var, hlt = hlt, llt = llt), - merge_function = "dplyr::inner_join", - join_keys = get_join_keys(data) + datasets = data, + select_validation_rule = list( + arm_var = ~ if (length(.) != 1 && length(.) != 2) + "Please select 1 or 2 treatment variable values", + hlt = ~ if (length(as.vector(merged$anl_input_r()$columns_source$llt)) + length(.) == 0) + "Please select at least one of \"LOW LEVEL TERM\" or \"HIGH LEVEL TERM\" variables.", + llt = ~ if (length(as.vector(merged$anl_input_r()$columns_source$hlt)) + length(.) == 0) + "Please select at least one of \"LOW LEVEL TERM\" or \"HIGH LEVEL TERM\" variables." + ) + ) + + iv_r <- reactive({ + iv <- shinyvalidate::InputValidator$new() + iv$add_rule("prune_freq", shinyvalidate::sv_required("Please provide an Incidence Rate between 0 and 100 (%).")) + iv$add_rule( + "prune_freq", + shinyvalidate::sv_between(0, 100, message_fmt = "Please provide an Incidence Rate between 0 and 100 (%).") + ) + iv$add_rule("prune_diff", shinyvalidate::sv_required("Please provide a Difference Rate between 0 and 100 (%).")) + iv$add_rule( + "prune_diff", + shinyvalidate::sv_between(0, 100, message_fmt = "Please provide a Difference Rate between 0 and 100 (%).") + ) + teal.transform::compose_and_enable_validators(iv, selector_list, c("arm_var", "hlt", "llt")) + }) + + anl_inputs <- teal.transform::merge_expression_srv( + datasets = data, + join_keys = get_join_keys(data), + selector_list = selector_list, + merge_function = "dplyr::inner_join" ) adsl_inputs <- teal.transform::merge_expression_module( @@ -666,6 +695,8 @@ srv_t_events_byterm <- function(id, ) validate_checks <- shiny::reactive({ + teal::validate_inputs(iv_r()) + adsl_filtered <- merged$anl_q()[[parentname]] anl_filtered <- merged$anl_q()[[dataname]] @@ -676,8 +707,6 @@ srv_t_events_byterm <- function(id, ) shiny::validate( - shiny::need(input_arm_var, "Please select a treatment variable"), - shiny::need(length(input_arm_var) <= 2, "Please limit treatment variables within two"), if (length(input_arm_var) >= 1) { shiny::need(is.factor(adsl_filtered[[input_arm_var[[1]]]]), "Treatment variable is not a factor.") }, @@ -690,20 +719,6 @@ srv_t_events_byterm <- function(id, ) } ) - teal::validate_has_elements( - input_level_term, - "Please select at least one of \"LOW LEVEL TERM\" or \"HIGH LEVEL TERM\" variables." - ) - shiny::validate( - shiny::need( - input$prune_freq >= 0 && input$prune_freq <= 100, - "Please provide an Incidence Rate between 0 and 100 (%)." - ), - shiny::need( - input$prune_diff >= 0 && input$prune_diff <= 100, - "Please provide a Difference Rate between 0 and 100 (%)." - ) - ) # validate inputs validate_standard_inputs(