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 42 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(value) if (length(value[[id_ref]]) == 0) "A reference arm must be selected")
iv$add_rule(input_id, function(value) if (length(value[[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
74 changes: 52 additions & 22 deletions R/tm_a_gee.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,13 @@ tm_a_gee <- function(label,
args <- as.list(environment())

data_extract_list <- list(
arm_var = teal.modules.clinical::cs_to_des_select(arm_var, dataname = parentname),
paramcd = teal.modules.clinical::cs_to_des_filter(paramcd, dataname = dataname),
id_var = teal.modules.clinical::cs_to_des_select(id_var, dataname = dataname),
visit_var = teal.modules.clinical::cs_to_des_select(visit_var, dataname = dataname),
cov_var = teal.modules.clinical::cs_to_des_select(cov_var, dataname = dataname, multiple = TRUE),
split_covariates = teal.modules.clinical::cs_to_des_select(teal.modules.clinical::split_choices(cov_var),
dataname = dataname, multiple = TRUE
),
aval_var = teal.modules.clinical::cs_to_des_select(aval_var, dataname = dataname)
arm_var = cs_to_des_select(arm_var, dataname = parentname),
paramcd = cs_to_des_filter(paramcd, dataname = dataname),
id_var = cs_to_des_select(id_var, dataname = dataname),
visit_var = cs_to_des_select(visit_var, dataname = dataname),
cov_var = cs_to_des_select(cov_var, dataname = dataname, multiple = TRUE),
split_covariates = cs_to_des_select(split_choices(cov_var),dataname = dataname, multiple = TRUE),
aval_var = cs_to_des_select(aval_var, dataname = dataname)
)

teal::module(
Expand Down Expand Up @@ -308,13 +306,11 @@ ui_gee <- function(id, ...) {
data_extract_spec = a$arm_var,
is_single_dataset = is_single_dataset_value
),
shinyjs::hidden(shiny::uiOutput(ns("arms_buckets"))),
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
shinyjs::hidden(
shiny::uiOutput(ns("arms_buckets")),
shiny::helpText(
id = ns("help_text"), "Multiple reference groups are automatically combined into a single group."
)
),
shinyjs::hidden(
),
shiny::checkboxInput(
ns("combine_comp_arms"),
"Combine all comparison groups?",
Expand Down Expand Up @@ -391,14 +387,14 @@ srv_gee <- function(id,

shiny::moduleServer(id, function(input, output, session) {
## split_covariates ----
shiny::observeEvent(input[[teal.modules.clinical::extract_input("cov_var", dataname)]],
shiny::observeEvent(input[[extract_input("cov_var", dataname)]],
ignoreNULL = FALSE,
{
# update covariates as actual variables
split_interactions_values <- teal.modules.clinical::split_interactions(
input[[teal.modules.clinical::extract_input("cov_var", dataname)]]
split_interactions_values <- split_interactions(
input[[extract_input("cov_var", dataname)]]
)
arm_var_value <- input[[teal.modules.clinical::extract_input("arm_var", parentname)]]
arm_var_value <- input[[extract_input("arm_var", parentname)]]
arm_in_cov <- length(intersect(split_interactions_values, arm_var_value)) >= 1L
if (arm_in_cov) {
split_covariates_selected <- setdiff(split_interactions_values, arm_var_value)
Expand All @@ -407,7 +403,7 @@ srv_gee <- function(id,
}
teal.widgets::updateOptionalSelectInput(
session,
inputId = teal.modules.clinical::extract_input("split_covariates", dataname),
inputId = extract_input("split_covariates", dataname),
selected = split_covariates_selected
)
}
Expand All @@ -418,15 +414,14 @@ srv_gee <- function(id,
session,
input,
output,
id_arm_var = teal.modules.clinical::extract_input("arm_var", parentname),
id_arm_var = extract_input("arm_var", parentname),
data = data[[parentname]],
arm_ref_comp = arm_ref_comp,
module = "tm_a_gee"
)

## data_merge_modules ----
anl_inputs <- teal.transform::merge_expression_module(
datasets = data,
selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(
arm_var = arm_var,
paramcd = paramcd,
Expand All @@ -435,6 +430,35 @@ srv_gee <- function(id,
split_covariates = split_covariates,
aval_var = aval_var
),
datasets = data,
select_validation_rule = list(
aval_var = shinyvalidate::sv_required("An analysis variable is required"),
arm_var = shinyvalidate::sv_required("A treatment variable is required"),
id_var = shinyvalidate::sv_required("A Subject identifier is required"),
visit_var = shinyvalidate::sv_required("A visit variable is required")
),
filter_validation_rule = list(
paramcd = shinyvalidate::sv_required("An endpoint is required")
)
)

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

anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
selector_list = selector_list,
merge_function = "dplyr::inner_join",
join_keys = get_join_keys(data)
)
Expand All @@ -461,10 +485,16 @@ srv_gee <- function(id,
# Initially hide the output title because there is no output yet.
shinyjs::show("gee_title")

# To do in production: add validations.
validate_checks <- shiny::reactive({
teal::validate_inputs(iv_r())

# To do in production: add validations.
NULL
})

## table_r ----
table_q <- shiny::reactive({
validate_checks()
output_table <- input$output_table
conf_level <- as.numeric(input$conf_level)
col_source <- merged$anl_input_r()$columns_source
Expand Down
Loading