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

tmc shinyvalidate #699

Merged
merged 74 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4525b8a
add shinyvalidate to DESC file
Dec 6, 2022
f7f34dd
NEWS
Dec 6, 2022
64cafde
tm_g_ci
Dec 6, 2022
f673677
use helper function from teal.transform
Dec 6, 2022
97c77e3
lineplot
Dec 6, 2022
d80b6b8
tm_t_events
Dec 6, 2022
e6c1150
update ci
Dec 7, 2022
4b5353b
Update NEWS.md
Dec 7, 2022
7c29dce
pp basic info
Dec 7, 2022
8422f6e
fix arm_ref_comp example
Dec 7, 2022
3b3d1ab
arm_ref_comp_observer
Dec 7, 2022
c918a78
arm ref comp in coxreg
Dec 7, 2022
0b95894
tm_g_forest_tte
Dec 7, 2022
5010a85
Merge branch 'main' into validator_test@main
Dec 7, 2022
add1d4b
more coxreg
Dec 8, 2022
8181992
summary modules (#701)
mhallal1 Dec 8, 2022
c3e2820
tm_g_ipp
Dec 8, 2022
35d6956
cox reg filtering
Dec 9, 2022
386223f
more coxreg
Dec 9, 2022
d173471
coxreg
Dec 9, 2022
09a6892
coxreg finished
Dec 9, 2022
9ac216c
add filter validation
mhallal1 Dec 9, 2022
2313434
Merge remote-tracking branch 'origin/validator_test@main' into valida…
mhallal1 Dec 9, 2022
0a2e17f
remove comment
mhallal1 Dec 9, 2022
1b98eb2
Merge branch 'main' into validator_test@main
Dec 13, 2022
fa4f81a
remove list of selectors when enabling
Dec 13, 2022
3d8b2b2
data to value
Dec 13, 2022
90cbf4f
tm_g_km
Dec 13, 2022
44e3bb4
tm_t_tte
Dec 13, 2022
8367325
tm_a_gee
Dec 14, 2022
a027a25
tm_t_shift_by_arm
Dec 14, 2022
5f38cf7
tm_t_shift_by_grade
Dec 14, 2022
3e37f23
tm_t_smq
BLAZEWIM Dec 14, 2022
af39cf0
tm_t_smq 2
BLAZEWIM Dec 14, 2022
510b41c
fix syntax error in roxygen example
Dec 14, 2022
0f470fe
tm_t_shift_by_arm_by_worst
BLAZEWIM Dec 15, 2022
8546feb
Merge branch 'validator_test@main' of https://github.com/insightsengi…
BLAZEWIM Dec 15, 2022
c4fa031
Update tm_t_shift_by_arm_by_worst.R
BLAZEWIM Dec 15, 2022
c9d044f
tm_t_events_summary
Dec 15, 2022
20133ce
tm_t_events_patyear
Dec 15, 2022
d7acaf9
tm_t_events_by_grade
Dec 15, 2022
37dd17f
tm_a_mmrm
Dec 16, 2022
c2cc890
fix tm_a_mmrm
Dec 16, 2022
1a447af
fixed coxrge
Dec 16, 2022
57f89c7
use selector_list not merge for validation
Dec 16, 2022
84e40df
mb tmc shinyvalidate (#704)
BLAZEWIM Dec 16, 2022
dadcb39
fix coxreg
Dec 20, 2022
5d647ea
remove anl_input from coxreg validation
Dec 20, 2022
2064988
contribution AC (#703)
chlebowa Dec 20, 2022
6c0cfb4
lintr
Dec 22, 2022
00998a8
styler and roxygen
Dec 22, 2022
a8d591b
code review changes
Dec 22, 2022
039be38
linter and linebreak in mmrm
Dec 22, 2022
cda3a61
update in barchart module
Dec 22, 2022
a057f20
styler
Dec 22, 2022
174957a
tweak barchart
Dec 22, 2022
4c240b8
fix summary
Dec 22, 2022
33b7a02
more module fixes
Dec 22, 2022
cddb97f
fix imports
Dec 22, 2022
d4582f4
fix imports
Dec 22, 2022
16e745e
lintr
Dec 22, 2022
566a92d
fix import
Dec 22, 2022
35c4625
linter
Dec 22, 2022
5a9b14f
handle missing selectors
gogonzo Jan 3, 2023
b3da6f8
Update R/tm_g_km.R
Jan 3, 2023
270881a
Update R/tm_g_km.R
Jan 3, 2023
0b17ac2
Merge branch 'main' into validator_test@main
Jan 3, 2023
ec596aa
Update R/tm_t_coxreg.R
Jan 3, 2023
9923bd8
remove bracket
Jan 3, 2023
5937a6e
Update R/tm_g_pp_vitals.R
Jan 3, 2023
9d8c206
ancova fix
Jan 5, 2023
1ae4998
Update R/tm_g_lineplot.R
Jan 5, 2023
fe986d4
Update R/tm_g_barchart_simple.R
chlebowa Jan 5, 2023
6ea9f99
barchart simple revert
Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Imports:
scales,
shiny,
shinyjs,
shinyvalidate,
shinyWidgets,
stats,
styler,
Expand Down Expand Up @@ -89,4 +90,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.2
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Replaced `synthetic_cdisc_data` with refactored `synthetic_cdisc_dataset` function to speed up dataset loading in tests/examples.
* Added new GEE module `tm_a_gee`.
* Added interface for selecting an interaction term to `tm_t_ancova`.
* Updated encodings input checks to use `shinyvalidate::InputValidator` instead of `shiny::validate` for better UI experience.

### Miscellaneous
* Package now uses `scda.2022` rather than `scda.2021` in SUGGESTS.
Expand Down
76 changes: 47 additions & 29 deletions R/arm_ref_comp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,52 @@
#' stop the whole observer if FALSE.
#' @param input_id (`character`) unique id that the buckets will be referenced with.
#' @param output_id (`character`) name of the UI id that the output will be written to.
#'
#' @return Returns a `shinyvalidate::InputValidator` which checks that there is at least one reference
#' and comparison arm
#' @keywords internal
#'
#' @examples
#' ds <- teal:::get_dummy_datasets()
#'
#' arm_ref_comp <- list(ARMCD = list(ref = "ARM A", comp = c("ARM B")))
#' arm_var <- choices_selected(c("ARM", "ARMCD"), "ARM")
#' if (interactive()) {
#' shinyApp(
#' ui = fluidPage(
#' teal.widgets::optionalSelectInput(
#' "arm",
#' "Treatment Variable",
#' choices = arm_var$choices,
#' selected = arm_var$selected
#' ),
#' shiny::uiOutput("arms_buckets"),
#' arm_var <- choices_selected(c("ARM", "ARMCD"), "ARMCD")
#'
#' adsl <- data.frame(ARM = c("ARM 1", "ARM2"), ARMCD = c("ARM A", "ARMB"))
#'
#' shiny::shinyApp(
#' ui = fluidPage(
#' teal.widgets::optionalSelectInput(
#' "arm",
#' "Treatment Variable",
#' choices = arm_var$choices,
#' selected = arm_var$selected
#' ),
#' server = function(input, output, session) {
#' shiny::isolate({
#' teal.modules.clinical:::arm_ref_comp_observer(
#' session,
#' input,
#' output,
#' id_arm_var = "arm",
#' datasets = ds,
#' arm_ref_comp = arm_ref_comp,
#' module = "example"
#' )
#' })
#' }
#' )
#' shiny::uiOutput("arms_buckets"),
#' shiny::textOutput("result")
#' ),
#' server = function(input, output, session) {
#'
#' iv_arm_ref <- teal.modules.clinical:::arm_ref_comp_observer(
#' session,
#' input,
#' output,
#' id_arm_var = "arm",
#' data = adsl,
#' arm_ref_comp = arm_ref_comp,
#' module = "example"
#' )
#'
#' output$result <- shiny::renderText({
#' iv <- shinyvalidate::InputValidator$new()
#' iv$add_validator(iv_arm_ref)
#' iv$enable()
#' teal::validate_inputs(iv)
#' "Valid selection has been made!"
#' })
#'
#' }
#' )
#' if (interactive()) {
#' shiny::shinyApp(ui, server)
#' }
arm_ref_comp_observer <- function(session,
input,
Expand All @@ -66,8 +79,12 @@ arm_ref_comp_observer <- function(session,
on_off = shiny::reactive(TRUE),
input_id = "buckets",
output_id = "arms_buckets") {
# uses observe because observeEvent evaluates only when on_off() is switched
# not necessarily when variables are dropped

iv <- shinyvalidate::InputValidator$new()
iv$add_rule(input_id, function(data) if (length(data[[id_ref]]) == 0) "A reference arm must be selected")
iv$add_rule(input_id, function(data) if (length(data[[id_comp]]) == 0) "A comparison arm must be selected")


output[[output_id]] <- shiny::renderUI({
if (!is.null(on_off()) && on_off()) {
df <- if (shiny::is.reactive(data)) {
Expand Down Expand Up @@ -112,6 +129,7 @@ arm_ref_comp_observer <- function(session,
)
}
})
return(iv)
}

#' Check if the Treatment variable is reference or compare
Expand Down
58 changes: 33 additions & 25 deletions R/tm_g_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ ui_g_ci <- function(id, ...) { # nolint
),
teal.transform::data_extract_ui(
id = ns("y_var"),
label = "Analyzed Value (y axis)",
label = "Analysis Value (y axis)",
data_extract_spec = args$y_var
),
teal.transform::data_extract_ui(
Expand Down Expand Up @@ -377,10 +377,30 @@ srv_g_ci <- function(id, # nolint
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(x_var = x_var, y_var = y_var, color = color),
join_keys = get_join_keys(data)
datasets = data,
select_validation_rule = list(
x_var = shinyvalidate::sv_required("Select a treatment (x axis)"),
y_var = shinyvalidate::sv_required("Select an analysis value (y axis)")
)
)

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("conf_level", shinyvalidate::sv_required("Please choose a confidence level"))
iv$add_rule(
"conf_level",
shinyvalidate::sv_between(0, 1, message_fmt = "Please choose a confidence level between 0 and 1")
nikolas-burkoff marked this conversation as resolved.
Show resolved Hide resolved
)
teal.transform::compose_and_enable_validators(iv, selector_list, c("x_var", "y_var"))
})

anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = get_join_keys(data),
selector_list = selector_list
)

anl_q <- reactive(
Expand All @@ -390,33 +410,21 @@ srv_g_ci <- function(id, # nolint
)
)

validate_data <- shiny::reactive({
shiny::validate(
shiny::need(
length(anl_inputs()$columns_source$x_var) > 0,
"Select a treatment (x axis)."
)
)
shiny::validate(
shiny::need(
length(anl_inputs()$columns_source$y_var) > 0,
"Select an analyzed value (y axis)."
)
)
all_q <- shiny::reactive({
teal::validate_inputs(iv_r())
teal::validate_has_data(anl_q()[["ANL"]], min_nrow = 2)

shiny::validate(shiny::need(
input$conf_level >= 0 && input$conf_level <= 1,
"Please choose a confidence level between 0 and 1"
))
})

all_q <- shiny::reactive({
validate_data()
x <- anl_inputs()$columns_source$x_var
y <- anl_inputs()$columns_source$y_var
color <- anl_inputs()$columns_source$color

shiny::validate(
asbates marked this conversation as resolved.
Show resolved Hide resolved
shiny::need(
!all(is.na(anl_q()[["ANL"]][[y]])),
"No valid data. Please check the filtering option for analysis value (y axis)"
)
)

x_label <- column_annotation_label(data[[attr(x, "dataname")]](), x)
y_label <- column_annotation_label(data[[attr(y, "dataname")]](), y)
color_label <- if (length(color)) {
Expand Down
48 changes: 30 additions & 18 deletions R/tm_g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ tm_g_lineplot <- function(label,
strata = cs_to_des_select(strata, dataname = parentname),
param = cs_to_des_filter(param, dataname = dataname),
x = cs_to_des_select(x, dataname = dataname, multiple = FALSE),
y = cs_to_des_select(y, dataname = dataname),
y = cs_to_des_select(y, dataname = dataname, multiple = FALSE),
y_unit = cs_to_des_select(y_unit, dataname = dataname),
paramcd = cs_to_des_select(paramcd, dataname = dataname)
)
Expand Down Expand Up @@ -518,10 +518,35 @@ srv_g_lineplot <- 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(x = x, y = y, strata = strata, paramcd = paramcd, y_unit = y_unit, param = param),
datasets = data,
select_validation_rule = list(
x = shinyvalidate::sv_required("Please select a single time variable"),
y = shinyvalidate::sv_required("Please select a single analysis variable"),
nikolas-burkoff marked this conversation as resolved.
Show resolved Hide resolved
strata = shinyvalidate::sv_required("Please select a treatment variable")
)
)

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("conf_level", shinyvalidate::sv_required("Please choose a confidence level"))
iv$add_rule(
"conf_level",
shinyvalidate::sv_between(
0, 1, message_fmt = "Please choose a confidence level between 0 and 1", inclusive = c(FALSE, FALSE)
)
)
iv$add_rule("interval", shinyvalidate::sv_required("Please select an interval for the midpoint statistic"))
iv$add_rule("whiskers", shinyvalidate::sv_required("At least one of the whiskers must be selected"))
teal.transform::compose_and_enable_validators(iv, selector_list, c("x", "y", "strata"))
})

anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = get_join_keys(data),
selector_list = selector_list,
merge_function = "dplyr::inner_join"
)

Expand All @@ -533,6 +558,8 @@ srv_g_lineplot <- function(id,
merged <- list(anl_input_r = anl_inputs, anl_q = anl_q)

validate_checks <- shiny::reactive({
teal::validate_inputs(iv_r())

adsl_filtered <- merged$anl_q()[[parentname]]
anl_filtered <- merged$anl_q()[[dataname]]

Expand All @@ -557,22 +584,7 @@ srv_g_lineplot <- function(id,
validate_args <- append(validate_args, list(min_n_levels_armvar = NULL))
}

# Validate whiskers
shiny::validate(shiny::need(length(input$whiskers) > 0, "At least one of the whiskers must be selected."))

# Validate interval
shiny::validate(shiny::need(length(input$interval) > 0, "Need to select an interval for the midpoint statistic."))

do.call(what = "validate_standard_inputs", validate_args)

shiny::validate(shiny::need(
input$conf_level > 0 && input$conf_level < 1,
"Please choose a confidence level between 0 and 1"
))

shiny::validate(shiny::need(checkmate::test_string(input_y), "Analysis variable should be a single column."))
shiny::validate(shiny::need(checkmate::test_string(input_x_var), "Time variable should be a single column."))

NULL
})

Expand Down
22 changes: 18 additions & 4 deletions R/tm_t_coxreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ srv_t_coxreg <- function(id,

shiny::moduleServer(id, function(input, output, session) {
# Observer to update reference and comparison arm input options.
arm_ref_comp_observer(
iv_arm_ref <- arm_ref_comp_observer(
nikolas-burkoff marked this conversation as resolved.
Show resolved Hide resolved
session,
input,
output,
Expand All @@ -766,9 +766,7 @@ srv_t_coxreg <- function(id,
module = "tm_t_coxreg"
)

anl_inputs <- teal.transform::merge_expression_module(
datasets = data,
join_keys = get_join_keys(data),
selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(
arm_var = arm_var,
paramcd = paramcd,
Expand All @@ -777,6 +775,20 @@ srv_t_coxreg <- function(id,
cnsr_var = cnsr_var,
cov_var = cov_var
),
datasets = data,
select_validation_rule = NULL
)

iv_r <- reactive({
nikolas-burkoff marked this conversation as resolved.
Show resolved Hide resolved
iv <- shinyvalidate::InputValidator$new()
iv$add_validator(iv_arm_ref)
teal.transform::compose_and_enable_validators(iv, selector_list, NULL)
})

anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = get_join_keys(data),
selector_list = selector_list,
merge_function = "dplyr::inner_join"
)

Expand Down Expand Up @@ -818,6 +830,8 @@ srv_t_coxreg <- function(id,

## Prepare the call evaluation environment ----
validate_checks <- shiny::reactive({
teal::validate_inputs(iv_r())

adsl_filtered <- merged$anl_q()[[parentname]]
anl_filtered <- merged$anl_q()[[dataname]]

Expand Down
Loading