Skip to content

Commit

Permalink
tm_t_events
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Burkoff committed Dec 6, 2022
1 parent 97c77e3 commit d80b6b8
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions R/tm_t_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]]

Expand All @@ -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.")
},
Expand All @@ -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(
Expand Down

0 comments on commit d80b6b8

Please sign in to comment.