diff --git a/R/tm_a_gee.R b/R/tm_a_gee.R index 42909bc981..b281ca2ad2 100644 --- a/R/tm_a_gee.R +++ b/R/tm_a_gee.R @@ -228,7 +228,7 @@ tm_a_gee <- function(label, aval_var = cs_to_des_select(aval_var, dataname = dataname) ) - teal::module( + ans <- teal::module( label = label, server = srv_gee, ui = ui_gee, @@ -245,6 +245,8 @@ tm_a_gee <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- FALSE + ans } ui_gee <- function(id, ...) { @@ -390,6 +392,8 @@ srv_gee <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + ## split_covariates ---- observeEvent(input[[extract_input("cov_var", dataname)]], ignoreNULL = FALSE, @@ -408,7 +412,7 @@ srv_gee <- function(id, teal.widgets::updateOptionalSelectInput( session, inputId = extract_input("split_covariates", dataname), - selected = split_covariates_selected + selected = restoreInput(ns(extract_input("split_covariates", dataname)), split_covariates_selected) ) } ) diff --git a/R/tm_a_mmrm.R b/R/tm_a_mmrm.R index c8ce92c6cc..3b81e053ad 100644 --- a/R/tm_a_mmrm.R +++ b/R/tm_a_mmrm.R @@ -579,7 +579,7 @@ tm_a_mmrm <- function(label, aval_var = cs_to_des_select(aval_var, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_mmrm, ui = ui_mmrm, @@ -600,6 +600,8 @@ tm_a_mmrm <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -846,6 +848,8 @@ srv_mmrm <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + # Reactive responsible for sending a disable/enable signal # to show R code and debug info buttons disable_r_code <- reactiveVal(FALSE) @@ -863,7 +867,7 @@ srv_mmrm <- function(id, teal.widgets::updateOptionalSelectInput( session, inputId = extract_input("split_covariates", dataname), - selected = split_covariates_selected + selected = restoreInput(ns(extract_input("split_covariates", dataname)), split_covariates_selected) ) }) diff --git a/R/tm_g_barchart_simple.R b/R/tm_g_barchart_simple.R index 7761c364c4..14ca4ef4da 100644 --- a/R/tm_g_barchart_simple.R +++ b/R/tm_g_barchart_simple.R @@ -174,7 +174,7 @@ tm_g_barchart_simple <- function(x = NULL, ) ui_args <- as.list(environment()) - module( + ans <- module( label = label, server = srv_g_barchart_simple, ui = ui_g_barchart_simple, @@ -190,6 +190,8 @@ tm_g_barchart_simple <- function(x = NULL, ), datanames = "all" ) + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal diff --git a/R/tm_g_ci.R b/R/tm_g_ci.R index a13d089689..34393f28bf 100644 --- a/R/tm_g_ci.R +++ b/R/tm_g_ci.R @@ -295,7 +295,7 @@ tm_g_ci <- function(label, args <- as.list(environment()) - module( + ans <- module( label = label, server = srv_g_ci, server_args = list( @@ -311,6 +311,8 @@ tm_g_ci <- function(label, ui_args = args, datanames = "all" ) + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal diff --git a/R/tm_g_forest_rsp.R b/R/tm_g_forest_rsp.R index 788fe477ff..6504a56a68 100644 --- a/R/tm_g_forest_rsp.R +++ b/R/tm_g_forest_rsp.R @@ -368,7 +368,7 @@ tm_g_forest_rsp <- function(label, strata_var = cs_to_des_select(strata_var, dataname = parentname, multiple = TRUE) ) - module( + ans <- module( label = label, ui = ui_g_forest_rsp, ui_args = c(data_extract_list, args), @@ -388,6 +388,10 @@ tm_g_forest_rsp <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # not bookmarkable b/c of arm_ref_comp_observer using teal.wigdets::draggable_buckets and JS therein + # https://github.com/insightsengineering/teal.widgets/issues/239 + attr(ans, "teal_bookmarkable") <- FALSE + ans } #' @keywords internal @@ -417,13 +421,7 @@ ui_g_forest_rsp <- function(id, ...) { data_extract_spec = a$aval_var, is_single_dataset = is_single_dataset_value ), - selectInput( - ns("responders"), - "Responders", - choices = c("CR", "PR"), - selected = c("CR", "PR"), - multiple = TRUE - ), + uiOutput(ns("container_responders")), teal.transform::data_extract_ui( id = ns("arm_var"), label = "Select Treatment Variable", @@ -509,6 +507,8 @@ srv_g_forest_rsp <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + # Setup arm variable selection, default reference arms, and default # comparison arms for encoding panel iv_arm_ref <- arm_ref_comp_observer( @@ -567,52 +567,48 @@ srv_g_forest_rsp <- function(id, teal.code::eval_code(code = as.expression(adsl_inputs()$expr)) }) - observeEvent( - eventExpr = c( - input[[extract_input("aval_var", "ADRS")]], - input[[extract_input("paramcd", paramcd$filter[[1]]$dataname, filter = TRUE)]] - ), - handlerExpr = { - req(anl_q()) - anl <- anl_q()[["ANL"]] - aval_var <- anl_inputs()$columns_source$aval_var - paramcd_level <- unlist(anl_inputs()$filter_info$paramcd[[1]]$selected) - if (length(paramcd_level) == 0) { - return(NULL) - } + output$container_responders <- renderUI({ + req(anl_q()) - sel_param <- if (is.list(default_responses)) { - default_responses[[paramcd_level]] - } else { - default_responses - } + anl <- anl_q()[["ANL"]] + aval_var <- anl_inputs()$columns_source$aval_var + paramcd_level <- unlist(anl_inputs()$filter_info$paramcd[[1]]$selected) + req(length(paramcd_level) != 0) - common_rsp <- if (is.list(sel_param)) { - sel_param$rsp - } else { - sel_param - } - responder_choices <- if (length(aval_var) == 0) { - character(0) - } else { - if ("levels" %in% names(sel_param)) { - if (length(intersect(unique(anl[[aval_var]]), sel_param$levels)) > 1) { - sel_param$levels - } else { - union(anl[[aval_var]], sel_param$levels) - } + sel_param <- if (is.list(default_responses)) { + default_responses[[paramcd_level]] + } else { + default_responses + } + + common_rsp <- if (is.list(sel_param)) { + sel_param$rsp + } else { + sel_param + } + responder_choices <- if (length(aval_var) == 0) { + character(0) + } else { + if ("levels" %in% names(sel_param)) { + if (length(intersect(unique(anl[[aval_var]]), sel_param$levels)) > 1) { + sel_param$levels } else { - unique(anl[[aval_var]]) + union(anl[[aval_var]], sel_param$levels) } + } else { + unique(anl[[aval_var]]) } - updateSelectInput( - session, "responders", - choices = responder_choices, - selected = intersect(responder_choices, common_rsp) - ) } - ) + + selectInput( + ns("responders"), + "Responders", + choices = responder_choices, + selected = intersect(responder_choices, common_rsp), + multiple = TRUE + ) + }) # Prepare the analysis environment (filter data, check data, populate envir). validate_checks <- reactive({ diff --git a/R/tm_g_forest_tte.R b/R/tm_g_forest_tte.R index 14dfc35d0b..a6c576a79b 100644 --- a/R/tm_g_forest_tte.R +++ b/R/tm_g_forest_tte.R @@ -351,7 +351,7 @@ tm_g_forest_tte <- function(label, time_unit_var = cs_to_des_select(time_unit_var, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_g_forest_tte, ui = ui_g_forest_tte, @@ -369,6 +369,10 @@ tm_g_forest_tte <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # pending https://github.com/insightsengineering/teal.transform/issues/210 + # likely also https://github.com/insightsengineering/teal.widgets/issues/239 + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal diff --git a/R/tm_g_ipp.R b/R/tm_g_ipp.R index 598fa913ac..3834170205 100644 --- a/R/tm_g_ipp.R +++ b/R/tm_g_ipp.R @@ -337,7 +337,7 @@ tm_g_ipp <- function(label, paramcd = cs_to_des_filter(paramcd, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_g_ipp, ui = ui_g_ipp, @@ -355,6 +355,8 @@ tm_g_ipp <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- FALSE + ans } #' @keywords internal diff --git a/R/tm_g_km.R b/R/tm_g_km.R index 2fe84400f4..05d9f7316f 100644 --- a/R/tm_g_km.R +++ b/R/tm_g_km.R @@ -360,7 +360,7 @@ tm_g_km <- function(label, time_unit_var = cs_to_des_select(time_unit_var, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_g_km, ui = ui_g_km, @@ -378,6 +378,10 @@ tm_g_km <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # pending https://github.com/insightsengineering/teal.transform/issues/210 + # likely also https://github.com/insightsengineering/teal.widgets/issues/239 + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index 807a66113b..04aa9ebef8 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -317,7 +317,7 @@ tm_g_lineplot <- function(label, paramcd = cs_to_des_select(paramcd, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_g_lineplot, ui = ui_g_lineplot, @@ -335,6 +335,9 @@ tm_g_lineplot <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # pending https://github.com/insightsengineering/teal.transform/issues/210 + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal diff --git a/R/tm_g_pp_adverse_events.R b/R/tm_g_pp_adverse_events.R index 30e8852f41..8abd94ff53 100644 --- a/R/tm_g_pp_adverse_events.R +++ b/R/tm_g_pp_adverse_events.R @@ -295,7 +295,7 @@ tm_g_pp_adverse_events <- function(label, decod = `if`(is.null(decod), NULL, cs_to_des_select(decod, dataname = dataname)) ) - module( + ans <- module( label = label, ui = ui_g_adverse_events, ui_args = c(data_extract_list, args), @@ -314,6 +314,9 @@ tm_g_pp_adverse_events <- function(label, ), datanames = c(dataname, parentname) ) + # presence of data extracts in UI may cause bookmarking problems as in other modules + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal @@ -346,12 +349,7 @@ ui_g_adverse_events <- function(id, ...) { "aeterm", "tox_grade", "causality", "outcome", "action", "time", "decod" )]), - teal.widgets::optionalSelectInput( - ns("patient_id"), - "Select Patient:", - multiple = FALSE, - options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) - ), + uiOutput(ns("container_patient_id")), teal.transform::data_extract_ui( id = ns("aeterm"), label = "Select AETERM variable:", @@ -443,32 +441,35 @@ srv_g_adverse_events <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + patient_id <- reactive(input$patient_id) - # Init patient_data_base <- reactive(unique(data()[[parentname]][[patient_col]])) - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = patient_data_base()[1] - ) - observeEvent(patient_data_base(), - handlerExpr = { - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { + output$container_patient_id <- renderUI({ + req(patient_data_base()) + + selected <- + if (!isTruthy(patient_id())) { + patient_data_base()[1L] + } else { + if (length(patient_data_base()) == 1) { patient_data_base() } else { intersect(patient_id(), patient_data_base()) } - ) - }, - ignoreInit = TRUE - ) + } + + teal.widgets::optionalSelectInput( + ns("patient_id"), + "Select Patient:", + choices = patient_data_base(), + selected = selected, + multiple = FALSE, + options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) + ) + }) # Adverse events tab ---- selector_list <- teal.transform::data_extract_multiple_srv( diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 78a17d15ec..c83495fe6d 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -522,7 +522,7 @@ tm_g_pp_patient_timeline <- function(label, dsrelday_end = `if`(is.null(dsrelday_end), NULL, cs_to_des_select(dsrelday_end, dataname = dataname_adcm)) ) - module( + ans <- module( label = label, ui = ui_g_patient_timeline, ui_args = c(data_extract_list, args), @@ -542,6 +542,9 @@ tm_g_pp_patient_timeline <- function(label, ), datanames = c(dataname_adcm, dataname_adae, parentname) ) + # pending https://github.com/insightsengineering/teal.transform/issues/211 + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -575,12 +578,7 @@ ui_g_patient_timeline <- function(id, ...) { "aerelday_start", "aerelday_end", "dsrelday_start", "dsrelday_end" )] ), - teal.widgets::optionalSelectInput( - ns("patient_id"), - "Select Patient:", - multiple = FALSE, - options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) - ), + uiOutput(ns("container_patient_id")), teal.transform::data_extract_ui( id = ns("cmdecod"), label = "Select Medication standardized term variable:", @@ -714,32 +712,35 @@ srv_g_patient_timeline <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + patient_id <- reactive(input$patient_id) - # Init patient_data_base <- reactive(unique(data()[[parentname]][[patient_col]])) - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = patient_data_base()[1] - ) - observeEvent(patient_data_base(), - handlerExpr = { - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { + output$container_patient_id <- renderUI({ + req(patient_data_base()) + + selected <- + if (!isTruthy(patient_id())) { + patient_data_base()[1] + } else { + if (length(patient_data_base()) == 1) { patient_data_base() } else { intersect(patient_id(), patient_data_base()) } - ) - }, - ignoreInit = TRUE - ) + } + + teal.widgets::optionalSelectInput( + ns("patient_id"), + "Select Patient:", + multiple = FALSE, + choices = patient_data_base(), + selected = selected, + options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) + ) + }) # Patient timeline tab ---- check_box <- reactive(input$relday_x_axis) diff --git a/R/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index d1856305c2..9540c97bf2 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -390,7 +390,7 @@ tm_g_pp_therapy <- function(label, cmendy = `if`(is.null(cmendy), NULL, cs_to_des_select(cmendy, dataname = dataname)) ) - module( + ans <- module( label = label, ui = ui_g_therapy, ui_args = c(data_extract_list, args), @@ -409,6 +409,9 @@ tm_g_pp_therapy <- function(label, ), datanames = c(dataname, parentname) ) + # presence of data extracts in UI may cause bookmarking problems as in other modules + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal @@ -444,12 +447,7 @@ ui_g_therapy <- function(id, ...) { "atirel", "cmdecod", "cmindc", "cmdose", "cmtrt", "cmdosu", "cmroute", "cmdosfrq", "cmstdy", "cmendy" )]), - teal.widgets::optionalSelectInput( - ns("patient_id"), - "Select Patient:", - multiple = FALSE, - options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) - ), + uiOutput(ns("container_patient_id")), teal.transform::data_extract_ui( id = ns("cmdecod"), label = "Select the medication decoding column:", @@ -559,30 +557,35 @@ srv_g_therapy <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { - patient_id <- reactive(input$patient_id) + ns <- session$ns - # Init patient_data_base <- reactive(unique(data()[[parentname]][[patient_col]])) - teal.widgets::updateOptionalSelectInput( - session, "patient_id", - choices = patient_data_base(), selected = patient_data_base()[1] - ) - observeEvent(patient_data_base(), - handlerExpr = { - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { + output$container_patient_id <- renderUI({ + req(patient_data_base()) + + selected <- + if (!isTruthy(patient_id())) { + patient_data_base()[1] + } else { + if (length(patient_data_base()) == 1) { patient_data_base() } else { intersect(patient_id(), patient_data_base()) } - ) - }, - ignoreInit = TRUE - ) + } + + teal.widgets::optionalSelectInput( + ns("patient_id"), + "Select Patient:", + choices = patient_data_base(), + selected = selected, + multiple = FALSE, + options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) + ) + }) + + patient_id <- reactive(input$patient_id) # Therapy tab ---- selector_list <- teal.transform::data_extract_multiple_srv( diff --git a/R/tm_g_pp_vitals.R b/R/tm_g_pp_vitals.R index 7b6501d570..4a5e0c4e0f 100644 --- a/R/tm_g_pp_vitals.R +++ b/R/tm_g_pp_vitals.R @@ -309,7 +309,7 @@ tm_g_pp_vitals <- function(label, xaxis = `if`(is.null(xaxis), NULL, cs_to_des_select(xaxis, dataname = dataname)) ) - module( + ans <- module( label = label, ui = ui_g_vitals, ui_args = c(data_extract_list, args), @@ -328,6 +328,9 @@ tm_g_pp_vitals <- function(label, ), datanames = c(dataname, parentname) ) + # presence of data extracts in UI may cause bookmarking problems as in other modules + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal @@ -348,12 +351,7 @@ ui_g_vitals <- function(id, ...) { ### tags$label("Encodings", class = "text-primary"), teal.transform::datanames_input(ui_args[c("paramcd", "aval_var", "xaxis")]), - teal.widgets::optionalSelectInput( - ns("patient_id"), - "Select Patient:", - multiple = FALSE, - options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) - ), + uiOutput(ns("container_patient_id")), teal.transform::data_extract_ui( id = ns("paramcd"), label = "Select PARAMCD variable:", @@ -412,32 +410,36 @@ srv_g_vitals <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { - patient_id <- reactive(input$patient_id) + ns <- session$ns + - # Init patient_data_base <- reactive(unique(data()[[parentname]][[patient_col]])) - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = patient_data_base()[1] - ) - observeEvent(patient_data_base(), - handlerExpr = { - teal.widgets::updateOptionalSelectInput( - session, - "patient_id", - choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { + output$container_patient_id <- renderUI({ + req(patient_data_base()) + + selected <- + if (!isTruthy(patient_id())) { + patient_data_base()[1] + } else { + if (length(patient_data_base()) == 1) { patient_data_base() } else { intersect(patient_id(), patient_data_base()) } - ) - }, - ignoreInit = TRUE - ) + } + + teal.widgets::optionalSelectInput( + ns("patient_id"), + "Select Patient:", + choices = patient_data_base(), + selected = selected, + multiple = FALSE, + options = shinyWidgets::pickerOptions(`liveSearch` = TRUE) + ) + }) + + patient_id <- reactive(input$patient_id) # Vitals tab ---- diff --git a/R/tm_t_abnormality.R b/R/tm_t_abnormality.R index 48c3b8770d..606ff9b491 100644 --- a/R/tm_t_abnormality.R +++ b/R/tm_t_abnormality.R @@ -359,7 +359,7 @@ tm_t_abnormality <- function(label, args <- as.list(environment()) - module( + ans <- module( label = label, ui = ui_t_abnormality, server = srv_t_abnormality, @@ -379,6 +379,9 @@ tm_t_abnormality <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # may be affected by https://github.com/insightsengineering/teal.widgets/issues/238 + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal @@ -506,6 +509,8 @@ srv_t_abnormality <- function(id, checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + selector_list <- teal.transform::data_extract_multiple_srv( data_extract = list( arm_var = arm_var, @@ -544,7 +549,7 @@ srv_t_abnormality <- function(id, session = session, inputId = "treatment_flag", choices = resolved$choices, - selected = resolved$selected + selected = restoreInput(ns("treatment_flag"), resolved$selected) ) }) diff --git a/R/tm_t_abnormality_by_worst_grade.R b/R/tm_t_abnormality_by_worst_grade.R index 3669a70971..a0469749a6 100644 --- a/R/tm_t_abnormality_by_worst_grade.R +++ b/R/tm_t_abnormality_by_worst_grade.R @@ -362,7 +362,7 @@ tm_t_abnormality_by_worst_grade <- function(label, # nolint: object_length. args <- as.list(environment()) - module( + ans <- module( label = label, ui = ui_t_abnormality_by_worst_grade, server = srv_t_abnormality_by_worst_grade, @@ -380,6 +380,9 @@ tm_t_abnormality_by_worst_grade <- function(label, # nolint: object_length. ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # may be affected by https://github.com/insightsengineering/teal.widgets/issues/238 + attr(ans, "teal_bookmarkable") <- TRUE + ans } #' @keywords internal @@ -456,12 +459,7 @@ ui_t_abnormality_by_worst_grade <- function(id, ...) { # nolint: object_length. data_extract_spec = a$id_var, is_single_dataset = is_single_dataset_value ), - teal.widgets::optionalSelectInput( - ns("worst_flag_indicator"), - label = "Value Indicating Worst Grade", - multiple = FALSE, - fixed_on_single = TRUE - ), + uiOutput(ns("container_worst_flag_indicator")), checkboxInput( ns("drop_arm_levels"), label = "Drop columns not in filtered analysis dataset", @@ -501,16 +499,22 @@ srv_t_abnormality_by_worst_grade <- function(id, # nolint: object_length. with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { - isolate({ - resolved <- teal.transform::resolve_delayed(worst_flag_indicator, as.list(data()@env)) - teal.widgets::updateOptionalSelectInput( - session = session, - inputId = "worst_flag_indicator", + ns <- session$ns + + + output$container_worst_flag_indicator <- renderUI({ + resolved <- isolate(teal.transform::resolve_delayed(worst_flag_indicator, as.list(data()@env))) + + teal.widgets::optionalSelectInput( + ns("worst_flag_indicator"), + label = "Value Indicating Worst Grade", choices = resolved$choices, - selected = resolved$selected + selected = resolved$selected, + multiple = FALSE, + fixed_on_single = TRUE ) }) diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index cd981dcf93..52898e0f43 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -549,7 +549,7 @@ tm_t_ancova <- function(label, interact_var = cs_to_des_select(interact_var, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_ancova, ui_args = c(data_extract_list, args), @@ -567,6 +567,10 @@ tm_t_ancova <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # affected by https://github.com/insightsengineering/teal.widgets/issues/239 + # An ATTEMPT was made but failed. Good luck. + attr(ans, "teal_bookmarkable") <- FALSE + ans } #' @keywords internal @@ -661,6 +665,8 @@ ui_ancova <- function(id, ...) { multiple = TRUE, fixed = FALSE ) + ### ATTEMPT AT ENABLING BOOKMARKING + # uiOutput(ns("container_interact_y")) # nolint: commented_code. ) ) ) @@ -694,9 +700,11 @@ srv_ancova <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + # Setup arm variable selection, default reference arms, and default # comparison arms for encoding panel. iv_arco <- arm_ref_comp_observer( @@ -796,13 +804,46 @@ srv_ancova <- function(id, session, "interact_y", selected = interact_select, - choices = interact_choices + choices = restoreInput(ns("interact_y"), interact_choices) ) } } } ) + ### ATTEMPT AT ENABLING BOOKMARKING + # nolint start: commented_code. + # # Render interact_y with choices set to all levels of selected interact_var + # output$container_interact_y <- renderUI({ + # req(!is.null(input$include_interact)) + # interact_var <- isolate(req(input$`interact_var-dataset_ADQS_singleextract-select`)) + # + # interact_choices <- sort(as.vector(unique(merged$anl_q()[[dataname]][[interact_var]]))) + # + # current_selection <- isolate(input$interact_y) + # interact_selected <- + # if (isTruthy(current_selection) && all(current_selection %in% interact_choices)) { + # current_selection + # } else { + # interact_choices[1L] + # } + # + # if (is.numeric(interact_choices)) { + # interact_choices <- NULL + # interact_selected <- NULL + # } + # + # teal.widgets::optionalSelectInput( + # ns("interact_y"), + # label = "Select Interaction y", + # choices = interact_choices, + # selected = interact_selected, + # multiple = TRUE, + # fixed = FALSE + # ) + # }) + # nolint end. + # Prepare the analysis environment (filter data, check data, populate envir). validate_checks <- reactive({ adsl_filtered <- merged$anl_q()[[parentname]] @@ -834,12 +875,12 @@ srv_ancova <- function(id, do.call(what = "validate_standard_inputs", validate_args) # Other validations. - validate(shiny::need( + validate(need( length(unique(adsl_filtered[[input_arm_var]])) > 1, "ANCOVA table needs at least 2 arm groups to make comparisons." )) # check that there is at least one record with no missing data - validate(shiny::need( + validate(need( !all(is.na(merged$anl_q()[["ANL"]][[input_aval_var]])), "ANCOVA table cannot be calculated as all values are missing." )) @@ -847,14 +888,14 @@ srv_ancova <- function(id, all_NA_dataset <- merged$anl_q()[["ANL"]] %>% # nolint: object_name. dplyr::group_by(dplyr::across(dplyr::all_of(c(input_avisit, input_arm_var)))) %>% dplyr::summarize(all_NA = all(is.na(.data[[input_aval_var]]))) - validate(shiny::need( + validate(need( !any(all_NA_dataset$all_NA), "ANCOVA table cannot be calculated as all values are missing for one visit for (at least) one arm." )) if (input$include_interact) { if (!is.null(input_interact_var) && length(input_interact_var) > 0) { - validate(shiny::need( + validate(need( !input_interact_var %in% c(input_avisit, input_paramcd) && length(as.vector(unique(anl_filtered[[input_interact_var]]))) > 1, paste( @@ -863,7 +904,7 @@ srv_ancova <- function(id, ) )) if (!all(is.numeric(as.vector(unique(anl_filtered[[input_interact_var]]))))) { - validate(shiny::need( + validate(need( !is.null(input$interact_y), paste( "Interaction y must be selected when a discrete variable is chosen for interact variable.", diff --git a/R/tm_t_binary_outcome.R b/R/tm_t_binary_outcome.R index a3f17c90e4..915c0d7f38 100644 --- a/R/tm_t_binary_outcome.R +++ b/R/tm_t_binary_outcome.R @@ -475,7 +475,7 @@ tm_t_binary_outcome <- function(label, strata_var = cs_to_des_select(strata_var, dataname = parentname, multiple = TRUE) ) - module( + ans <- module( label = label, ui = ui_t_binary_outcome, ui_args = c(data_extract_list, args), @@ -496,6 +496,9 @@ tm_t_binary_outcome <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + # pending https://github.com/insightsengineering/teal.widgets/issues/239 + attr(ans, "teal_bookmarkable") <- FALSE + ans } #' @keywords internal @@ -523,13 +526,7 @@ ui_t_binary_outcome <- function(id, ...) { data_extract_spec = a$paramcd, is_single_dataset = is_single_dataset_value ), - selectInput( - ns("responders"), - "Responders", - choices = NULL, - selected = NULL, - multiple = TRUE - ), + uiOutput(ns("container_responders")), teal.transform::data_extract_ui( id = ns("arm_var"), label = "Select Treatment Variable", @@ -709,9 +706,11 @@ srv_t_binary_outcome <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + # Setup arm variable selection, default reference arms, and default # comparison arms for encoding panel iv_arm_ref <- arm_ref_comp_observer( @@ -769,45 +768,42 @@ srv_t_binary_outcome <- function(id, teal.code::eval_code(as.expression(adsl_inputs()$expr)) }) - observeEvent( - c( - input[[extract_input("aval_var", "ADRS")]], - input[[extract_input("paramcd", paramcd$filter[[1]]$dataname, filter = TRUE)]] - ), - handlerExpr = { - anl <- anl_q()[["ANL"]] - aval_var <- anl_inputs()$columns_source$aval_var - paramcd <- input[[extract_input("paramcd", paramcd$filter[[1]]$dataname, filter = TRUE)]] - sel_param <- if (is.list(default_responses) && (!is.null(paramcd))) { - default_responses[[paramcd]] - } else { - default_responses - } - common_rsp <- if (is.list(sel_param)) { - sel_param$rsp - } else { - sel_param - } - responder_choices <- if (length(aval_var) == 0) { - character(0) - } else { - if ("levels" %in% names(sel_param)) { - if (length(intersect(unique(anl[[aval_var]]), sel_param$levels)) > 1) { - sel_param$levels - } else { - unique(anl[[aval_var]]) - } + output$container_responders <- renderUI({ + anl <- req(anl_q()[["ANL"]]) + aval_var <- req(anl_inputs()$columns_source$aval_var) + paramcd <- req(input[[extract_input("paramcd", paramcd$filter[[1]]$dataname, filter = TRUE)]]) + sel_param <- if (is.list(default_responses) && (!is.null(paramcd))) { + default_responses[[paramcd]] + } else { + default_responses + } + common_rsp <- if (is.list(sel_param)) { + sel_param$rsp + } else { + sel_param + } + responder_choices <- if (length(aval_var) == 0) { + character(0) + } else { + if ("levels" %in% names(sel_param)) { + if (length(intersect(unique(anl[[aval_var]]), sel_param$levels)) > 1) { + sel_param$levels } else { unique(anl[[aval_var]]) } + } else { + unique(anl[[aval_var]]) } - updateSelectInput( - session, "responders", - choices = responder_choices, - selected = intersect(responder_choices, common_rsp) - ) } - ) + + selectInput( + ns("responders"), + "Responders", + choices = responder_choices, + selected = common_rsp, + multiple = TRUE + ) + }) validate_check <- reactive({ teal::validate_inputs(iv_r()) diff --git a/R/tm_t_coxreg.R b/R/tm_t_coxreg.R index d71ff7ba19..53245cca33 100644 --- a/R/tm_t_coxreg.R +++ b/R/tm_t_coxreg.R @@ -537,7 +537,7 @@ tm_t_coxreg <- function(label, cov_var = cs_to_des_select(cov_var, dataname = parentname, multiple = TRUE, ordered = TRUE) ) - module( + ans <- module( label = label, server = srv_t_coxreg, ui = ui_t_coxreg, @@ -555,6 +555,8 @@ tm_t_coxreg <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -714,7 +716,7 @@ srv_t_coxreg <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { # Observer to update reference and comparison arm input options. @@ -903,7 +905,7 @@ srv_t_coxreg <- function(id, } else { c(sum(arm_n[unlist(input$buckets$Ref)]), arm_n[unlist(input$buckets$Comp)]) } - validate(shiny::need( + validate(need( all(anl_arm_n >= 2), "Each treatment group should have at least 2 records." )) diff --git a/R/tm_t_events.R b/R/tm_t_events.R index 8e02434fce..7fd98cda57 100644 --- a/R/tm_t_events.R +++ b/R/tm_t_events.R @@ -549,7 +549,7 @@ tm_t_events <- function(label, llt = cs_to_des_select(llt, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_t_events_byterm, server = srv_t_events_byterm, @@ -570,6 +570,8 @@ tm_t_events <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -675,7 +677,7 @@ srv_t_events_byterm <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { selector_list <- teal.transform::data_extract_multiple_srv( diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index e393bf62c7..b280bf40a4 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -890,7 +890,7 @@ tm_t_events_by_grade <- function(label, grade = cs_to_des_select(grade, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_t_events_by_grade, ui = ui_t_events_by_grade, @@ -909,6 +909,8 @@ tm_t_events_by_grade <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -1019,7 +1021,7 @@ srv_t_events_by_grade <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { selector_list <- teal.transform::data_extract_multiple_srv( diff --git a/R/tm_t_events_patyear.R b/R/tm_t_events_patyear.R index dcd3510723..f0982363be 100644 --- a/R/tm_t_events_patyear.R +++ b/R/tm_t_events_patyear.R @@ -260,7 +260,7 @@ tm_t_events_patyear <- function(label, events_var = cs_to_des_select(events_var, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_events_patyear, ui_args = c(data_extract_list, args), @@ -278,6 +278,8 @@ tm_t_events_patyear <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -399,9 +401,11 @@ srv_events_patyear <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + observeEvent(anl_q(), { data_anl <- merged$anl_q()[["ANL"]] aval_unit_var <- merged$anl_input_r()$columns_source$avalu_var @@ -413,7 +417,7 @@ srv_events_patyear <- function(id, session, "input_time_unit", choices = choices, - selected = choices[1] + selected = restoreInput(ns("input_time_unit"), choices[1]) ) } }) diff --git a/R/tm_t_events_summary.R b/R/tm_t_events_summary.R index b420f7c6d5..e3b05816c4 100644 --- a/R/tm_t_events_summary.R +++ b/R/tm_t_events_summary.R @@ -655,7 +655,7 @@ tm_t_events_summary <- function(label, llt = cs_to_des_select(llt, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_t_events_summary, ui_args = c(data_extract_list, args), @@ -673,6 +673,8 @@ tm_t_events_summary <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -807,7 +809,7 @@ srv_t_events_summary <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { data_extract_vars <- list( diff --git a/R/tm_t_exposure.R b/R/tm_t_exposure.R index f8e8116686..d37746a1aa 100644 --- a/R/tm_t_exposure.R +++ b/R/tm_t_exposure.R @@ -354,7 +354,7 @@ tm_t_exposure <- function(label, ) args <- as.list(environment()) - module( + ans <- module( label = label, ui = ui_t_exposure, server = srv_t_exposure, @@ -374,6 +374,8 @@ tm_t_exposure <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } @@ -484,7 +486,7 @@ srv_t_exposure <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { rule_intersection <- function(other) { function(value) { diff --git a/R/tm_t_logistic.R b/R/tm_t_logistic.R index 9c4ecec947..7be74beea7 100644 --- a/R/tm_t_logistic.R +++ b/R/tm_t_logistic.R @@ -317,7 +317,7 @@ tm_t_logistic <- function(label, avalc_var = cs_to_des_select(avalc_var, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_t_logistic, ui = ui_t_logistic, @@ -334,6 +334,8 @@ tm_t_logistic <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -448,9 +450,11 @@ srv_t_logistic <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + # Observer to update reference and comparison arm input options. iv_arco <- arm_ref_comp_observer( session, @@ -554,7 +558,7 @@ srv_t_logistic <- function(id, updateSelectInput( session, "responders", choices = responder_choices, - selected = responder_sel + selected = restoreInput(ns("responders"), responder_sel) ) }) @@ -632,7 +636,7 @@ srv_t_logistic <- function(id, } else { c(sum(arm_n[unlist(input$buckets$Ref)]), arm_n[unlist(input$buckets$Comp)]) } - validate(shiny::need( + validate(need( all(anl_arm_n >= 2), "Each treatment group should have at least 2 records." )) diff --git a/R/tm_t_mult_events.R b/R/tm_t_mult_events.R index 15c41951db..b5b8f69567 100644 --- a/R/tm_t_mult_events.R +++ b/R/tm_t_mult_events.R @@ -370,7 +370,7 @@ tm_t_mult_events <- function(label, llt = cs_to_des_select(llt, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_t_mult_events_byterm, server = srv_t_mult_events_byterm, @@ -389,6 +389,8 @@ tm_t_mult_events <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -477,7 +479,7 @@ srv_t_mult_events_byterm <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { selector_list <- teal.transform::data_extract_multiple_srv( diff --git a/R/tm_t_pp_basic_info.R b/R/tm_t_pp_basic_info.R index 9c7d4b1ee4..a0f005482a 100644 --- a/R/tm_t_pp_basic_info.R +++ b/R/tm_t_pp_basic_info.R @@ -110,7 +110,7 @@ tm_t_pp_basic_info <- function(label, vars = `if`(is.null(vars), NULL, cs_to_des_select(vars, dataname = dataname, multiple = TRUE)) ) - module( + ans <- module( label = label, ui = ui_t_basic_info, ui_args = c(data_extract_list, args), @@ -125,6 +125,8 @@ tm_t_pp_basic_info <- function(label, ), datanames = dataname ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -178,9 +180,11 @@ srv_t_basic_info <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + patient_id <- reactive(input$patient_id) # Init @@ -189,7 +193,7 @@ srv_t_basic_info <- function(id, session, "patient_id", choices = patient_data_base(), - selected = patient_data_base()[1] + selected = restoreInput(ns("patient_id"), patient_data_base()[1]) ) observeEvent(patient_data_base(), @@ -198,11 +202,14 @@ srv_t_basic_info <- function(id, session, "patient_id", choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { - patient_data_base() - } else { - intersect(patient_id(), patient_data_base()) - } + selected = restoreInput( + ns("patient_id"), + if (length(patient_data_base()) == 1) { + patient_data_base() + } else { + intersect(patient_id(), patient_data_base()) + } + ) ) }, ignoreInit = TRUE diff --git a/R/tm_t_pp_laboratory.R b/R/tm_t_pp_laboratory.R index cdb1021d46..f69388a29a 100644 --- a/R/tm_t_pp_laboratory.R +++ b/R/tm_t_pp_laboratory.R @@ -257,7 +257,7 @@ tm_t_pp_laboratory <- function(label, anrind = `if`(is.null(anrind), NULL, cs_to_des_select(anrind, dataname = dataname)) ) - module( + ans <- module( label = label, ui = ui_g_laboratory, ui_args = c(data_extract_list, args), @@ -273,6 +273,8 @@ tm_t_pp_laboratory <- function(label, ), datanames = c(dataname, parentname) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -374,9 +376,11 @@ srv_g_laboratory <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + patient_id <- reactive(input$patient_id) # Init @@ -385,7 +389,7 @@ srv_g_laboratory <- function(id, session, "patient_id", choices = patient_data_base(), - selected = patient_data_base()[1] + selected = restoreInput(ns("patient_id"), patient_data_base()[1]) ) observeEvent(patient_data_base(), @@ -394,11 +398,14 @@ srv_g_laboratory <- function(id, session, "patient_id", choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { - patient_data_base() - } else { - intersect(patient_id(), patient_data_base()) - } + selected = restoreInput( + ns("patient_id"), + if (length(patient_data_base()) == 1) { + patient_data_base() + } else { + intersect(patient_id(), patient_data_base()) + } + ) ) }, ignoreInit = TRUE @@ -413,7 +420,7 @@ srv_g_laboratory <- function(id, session, "round_value", choices = seq(0, max_decimal), - selected = min(4, max_decimal) + selected = restoreInput(ns("round_value"), min(4, max_decimal)) ) # Laboratory values tab ---- diff --git a/R/tm_t_pp_medical_history.R b/R/tm_t_pp_medical_history.R index 8fdcb57c99..fef34d19d4 100644 --- a/R/tm_t_pp_medical_history.R +++ b/R/tm_t_pp_medical_history.R @@ -155,7 +155,7 @@ tm_t_pp_medical_history <- function(label, mhdistat = `if`(is.null(mhdistat), NULL, cs_to_des_select(mhdistat, dataname = dataname)) ) - module( + ans <- module( label = label, ui = ui_t_medical_history, ui_args = c(data_extract_list, args), @@ -171,6 +171,8 @@ tm_t_pp_medical_history <- function(label, ), datanames = c(dataname, parentname) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -242,16 +244,19 @@ srv_t_medical_history <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + patient_id <- reactive(input$patient_id) # Init patient_data_base <- reactive(unique(data()[[parentname]][[patient_col]])) teal.widgets::updateOptionalSelectInput( session, "patient_id", - choices = patient_data_base(), selected = patient_data_base()[1] + choices = patient_data_base(), + selected = restoreInput(ns("patient_id"), patient_data_base()[1]) ) observeEvent(patient_data_base(), @@ -260,11 +265,14 @@ srv_t_medical_history <- function(id, session, "patient_id", choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { - patient_data_base() - } else { - intersect(patient_id(), patient_data_base()) - } + selected = restoreInput( + ns("patient_id"), + if (length(patient_data_base()) == 1) { + patient_data_base() + } else { + intersect(patient_id(), patient_data_base()) + } + ) ) }, ignoreInit = TRUE diff --git a/R/tm_t_pp_prior_medication.R b/R/tm_t_pp_prior_medication.R index f0937e671f..836e72964b 100644 --- a/R/tm_t_pp_prior_medication.R +++ b/R/tm_t_pp_prior_medication.R @@ -145,7 +145,7 @@ tm_t_pp_prior_medication <- function(label, cmstdy = `if`(is.null(cmstdy), NULL, cs_to_des_select(cmstdy, dataname = dataname)) ) - module( + ans <- module( label = label, ui = ui_t_prior_medication, ui_args = c(data_extract_list, args), @@ -161,6 +161,8 @@ tm_t_pp_prior_medication <- function(label, ), datanames = c(dataname, parentname) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -240,9 +242,11 @@ srv_t_prior_medication <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + patient_id <- reactive(input$patient_id) selector_list <- teal.transform::data_extract_multiple_srv( @@ -273,7 +277,7 @@ srv_t_prior_medication <- function(id, session, "patient_id", choices = patient_data_base(), - selected = patient_data_base()[1] + selected = restoreInput(ns("patient_id"), patient_data_base()[1]) ) observeEvent(patient_data_base(), @@ -282,11 +286,14 @@ srv_t_prior_medication <- function(id, session, "patient_id", choices = patient_data_base(), - selected = if (length(patient_data_base()) == 1) { - patient_data_base() - } else { - intersect(patient_id(), patient_data_base()) - } + selected = restoreInput( + ns("patient_id"), + if (length(patient_data_base()) == 1) { + patient_data_base() + } else { + intersect(patient_id(), patient_data_base()) + } + ) ) }, ignoreInit = TRUE diff --git a/R/tm_t_shift_by_arm.R b/R/tm_t_shift_by_arm.R index 79c9ad30c3..8ecaeabc00 100644 --- a/R/tm_t_shift_by_arm.R +++ b/R/tm_t_shift_by_arm.R @@ -302,7 +302,7 @@ tm_t_shift_by_arm <- function(label, baseline_var = cs_to_des_select(baseline_var, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_shift_by_arm, ui = ui_shift_by_arm, @@ -321,6 +321,8 @@ tm_t_shift_by_arm <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -435,8 +437,10 @@ srv_shift_by_arm <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + selector_list <- teal.transform::data_extract_multiple_srv( data_extract = list( arm_var = arm_var, @@ -465,7 +469,7 @@ srv_shift_by_arm <- function(id, session = session, inputId = "treatment_flag", choices = resolved$choices, - selected = resolved$selected + selected = restoreInput(ns("treatment_flag"), resolved$selected) ) }) diff --git a/R/tm_t_shift_by_arm_by_worst.R b/R/tm_t_shift_by_arm_by_worst.R index 8f2642c276..f71dccd372 100644 --- a/R/tm_t_shift_by_arm_by_worst.R +++ b/R/tm_t_shift_by_arm_by_worst.R @@ -314,7 +314,7 @@ tm_t_shift_by_arm_by_worst <- function(label, ) - module( + ans <- module( label = label, server = srv_shift_by_arm_by_worst, ui = ui_shift_by_arm_by_worst, @@ -333,6 +333,8 @@ tm_t_shift_by_arm_by_worst <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -455,8 +457,10 @@ srv_shift_by_arm_by_worst <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + selector_list <- teal.transform::data_extract_multiple_srv( data_extract = list( arm_var = arm_var, @@ -485,7 +489,7 @@ srv_shift_by_arm_by_worst <- function(id, session = session, inputId = "treatment_flag", choices = resolved$choices, - selected = resolved$selected + selected = restoreInput(ns("treatment_flag"), resolved$selected) ) }) diff --git a/R/tm_t_shift_by_grade.R b/R/tm_t_shift_by_grade.R index ce05337039..177006a48d 100644 --- a/R/tm_t_shift_by_grade.R +++ b/R/tm_t_shift_by_grade.R @@ -602,7 +602,7 @@ tm_t_shift_by_grade <- function(label, base_toxgrade_var = cs_to_des_select(base_toxgrade_var, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_t_shift_by_grade, server = srv_t_shift_by_grade, @@ -620,6 +620,8 @@ tm_t_shift_by_grade <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -752,7 +754,7 @@ srv_t_shift_by_grade <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { selector_list <- teal.transform::data_extract_multiple_srv( diff --git a/R/tm_t_smq.R b/R/tm_t_smq.R index d7fc866057..5f7b117e4a 100644 --- a/R/tm_t_smq.R +++ b/R/tm_t_smq.R @@ -416,7 +416,7 @@ tm_t_smq <- function(label, llt = cs_to_des_select(llt, dataname = dataname) ) - module( + ans <- module( label = label, ui = ui_t_smq, server = srv_t_smq, @@ -434,6 +434,8 @@ tm_t_smq <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -542,7 +544,7 @@ srv_t_smq <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { selector_list <- teal.transform::data_extract_multiple_srv( data_extract = list( diff --git a/R/tm_t_summary.R b/R/tm_t_summary.R index 326556afc6..fb4b6ca433 100644 --- a/R/tm_t_summary.R +++ b/R/tm_t_summary.R @@ -280,7 +280,7 @@ tm_t_summary <- function(label, summarize_vars = cs_to_des_select(summarize_vars, dataname = dataname, multiple = TRUE, ordered = TRUE) ) - module( + ans <- module( label = label, server = srv_summary, ui = ui_summary, @@ -298,6 +298,8 @@ tm_t_summary <- function(label, ), datanames = c(dataname, parentname) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -403,7 +405,7 @@ srv_summary <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { selector_list <- teal.transform::data_extract_multiple_srv( data_extract = list(arm_var = arm_var, summarize_vars = summarize_vars), diff --git a/R/tm_t_summary_by.R b/R/tm_t_summary_by.R index 3d1b4fda7e..f976084972 100644 --- a/R/tm_t_summary_by.R +++ b/R/tm_t_summary_by.R @@ -433,7 +433,7 @@ tm_t_summary_by <- function(label, summarize_vars = cs_to_des_select(summarize_vars, dataname = dataname, multiple = TRUE, ordered = TRUE) ) - module( + ans <- module( label = label, ui = ui_summary_by, ui_args = c(data_extract_list, args), @@ -451,6 +451,8 @@ tm_t_summary_by <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -596,7 +598,7 @@ srv_summary_by <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { vars <- list(arm_var = arm_var, id_var = id_var, summarize_vars = summarize_vars, by_vars = by_vars) @@ -673,7 +675,7 @@ srv_summary_by <- function(id, ) if (input$parallel_vars) { - validate(shiny::need( + validate(need( all(vapply(anl_filtered[input_summarize_vars], is.numeric, logical(1))), "Summarize variables must all be numeric to display in parallel columns." )) diff --git a/R/tm_t_tte.R b/R/tm_t_tte.R index e4fc6f5b91..20beb88746 100644 --- a/R/tm_t_tte.R +++ b/R/tm_t_tte.R @@ -521,7 +521,7 @@ tm_t_tte <- function(label, time_unit_var = cs_to_des_select(time_unit_var, dataname = dataname) ) - module( + ans <- module( label = label, server = srv_t_tte, ui = ui_t_tte, @@ -540,6 +540,8 @@ tm_t_tte <- function(label, ), datanames = teal.transform::get_extract_datanames(data_extract_list) ) + attr(ans, "teal_bookmarkable") <- NULL + ans } #' @keywords internal @@ -753,7 +755,7 @@ srv_t_tte <- function(id, with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") - checkmate::assert_class(shiny::isolate(data()), "teal_data") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { # Setup arm variable selection, default reference arms, and default # comparison arms for encoding panel @@ -885,7 +887,7 @@ srv_t_tte <- function(id, do.call(what = "validate_standard_inputs", validate_args) # check that there is at least one record with no missing data - validate(shiny::need( + validate(need( !all(is.na(anl[[input_aval_var]])), "ANCOVA table cannot be calculated as all values are missing." )) diff --git a/R/validate_standard_inputs.R b/R/validate_standard_inputs.R index 9d70e60d9c..467a7ca5d0 100644 --- a/R/validate_standard_inputs.R +++ b/R/validate_standard_inputs.R @@ -76,7 +76,7 @@ validate_standard_inputs <- function(adsl, #' @keywords internal #' validate_arm <- function(arm_vec) { - validate(shiny::need(is.factor(arm_vec), "Treatment variable is not a factor")) + validate(need(is.factor(arm_vec), "Treatment variable is not a factor")) validate( need( all(trimws(levels(arm_vec)) != ""), diff --git a/man/template_g_km.Rd b/man/template_g_km.Rd index 514acfc6f0..b7dd855ceb 100644 --- a/man/template_g_km.Rd +++ b/man/template_g_km.Rd @@ -49,9 +49,9 @@ template_g_km( \item{cnsr_var}{(\code{character})\cr name of the censoring variable.} -\item{xticks}{(\code{numeric}, \code{number}, or \code{NULL})\cr numeric vector of ticks or single number with spacing -between ticks on the x axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine -an optimal tick position on the x axis.} +\item{xticks}{(\code{numeric}, \code{number}, or \code{NULL})\cr numeric vector of tick positions or single number with spacing +between ticks on the x-axis. If \code{NULL} (default), \code{\link[labeling:extended]{labeling::extended()}} is used to determine +optimal tick positions on the x-axis.} \item{strata_var}{(\code{character})\cr names of the variables for stratified analysis.} @@ -66,11 +66,12 @@ an optimal tick position on the x axis.} \item{ties}{(\code{string})\cr among \code{exact} (equivalent to \code{DISCRETE} in SAS), \code{efron} and \code{breslow}, see \code{\link[survival:coxph]{survival::coxph()}}. Note: there is no equivalent of SAS \code{EXACT} method in R.} -\item{xlab}{(\code{string})\cr label of x-axis.} +\item{xlab}{(\code{string})\cr x-axis label.} \item{time_unit_var}{(\code{character})\cr name of the variable representing time units.} -\item{yval}{(\code{string})\cr value of y-axis. Options are \code{Survival} (default) and \code{Failure} probability.} +\item{yval}{(\code{string})\cr type of plot, to be plotted on the y-axis. Options are \code{Survival} (default) and \code{Failure} +probability.} \item{pval_method}{(\code{string})\cr the method used for estimation of p.values; \code{wald} (default) or \code{likelihood}.} @@ -79,13 +80,13 @@ median survival time per group.} \item{annot_coxph}{(\code{flag})\cr add the annotation table from a \code{\link[survival:coxph]{survival::coxph()}} model.} -\item{position_coxph}{(\code{numeric})\cr x and y positions for plotting \code{\link[survival:coxph]{survival::coxph()}} model.} +\item{position_coxph}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use the \code{x} and \code{y} elements of +\code{control_annot_coxph} instead.} -\item{width_annots}{(named \code{list} of \code{unit}s)\cr a named list of widths for annotation tables with names \code{surv_med} -(median survival time table) and \code{coxph} (\code{\link[survival:coxph]{survival::coxph()}} model table), where each value is the width -(in units) to implement when printing the annotation table.} +\item{width_annots}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use the \code{w} element of \code{control_annot_surv_med} +(for surv_med) and \code{control_annot_coxph} (for coxph)."} -\item{ci_ribbon}{(\code{flag})\cr draw the confidence interval around the Kaplan-Meier curve.} +\item{ci_ribbon}{(\code{flag})\cr whether the confidence interval should be drawn around the Kaplan-Meier curve.} \item{title}{(\code{character})\cr title of the output.} }