From 77ab3bdfee840a0e4842dafc2177dbc773289b70 Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Mon, 18 Mar 2024 13:15:03 +0100 Subject: [PATCH 1/3] define ns in modules --- R/adtteSpec.R | 4 +++- R/pca.R | 4 +++- R/quality.R | 4 +++- R/sampleVarSpec.R | 6 ++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/adtteSpec.R b/R/adtteSpec.R index c31e0c43..ffda0b61 100644 --- a/R/adtteSpec.R +++ b/R/adtteSpec.R @@ -263,6 +263,8 @@ adtteSpecServer <- function(id, # nolint checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + # Join ADTTE with gene data. adtte_joined <- reactive({ experiment_data <- experiment_data() @@ -305,7 +307,7 @@ adtteSpecServer <- function(id, # nolint # Start by disabling selection, will be overriden if there are valid choices. session$sendCustomMessage( "toggle_dropdown", - list(input_id = session$ns("paramcd"), disabled = TRUE) + list(input_id = ns("paramcd"), disabled = TRUE) ) # Once available endpoints change, we update choices (and also the selection diff --git a/R/pca.R b/R/pca.R index 1e1871e5..125999d0 100644 --- a/R/pca.R +++ b/R/pca.R @@ -161,8 +161,10 @@ srv_g_pca <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/quality.R b/R/quality.R index 8c5dc805..234f3cd6 100644 --- a/R/quality.R +++ b/R/quality.R @@ -203,8 +203,10 @@ srv_g_quality <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/sampleVarSpec.R b/R/sampleVarSpec.R index 72d0193c..8712a2f2 100644 --- a/R/sampleVarSpec.R +++ b/R/sampleVarSpec.R @@ -288,6 +288,8 @@ sampleVarSpecServer <- function(id, # nolint assert_string(label_modal_title) moduleServer(id, function(input, output, session) { + ns <- session$ns + to_observe <- reactive({ list(experiment_name(), original_data()) }) @@ -383,7 +385,7 @@ sampleVarSpecServer <- function(id, # nolint } modalDialog( shinyRadioMatrix::radioMatrixInput( - session$ns("comb_assignment"), + ns("comb_assignment"), rowIDs = sample_var_levels, rowIDsName = "Original levels", rowLLabels = rep("", length = length(sample_var_levels)), @@ -393,7 +395,7 @@ sampleVarSpecServer <- function(id, # nolint tags$span(label_modal_title), footer = tagList( modalButton("Cancel"), - actionButton(session$ns("ok"), "OK") + actionButton(ns("ok"), "OK") ), include_js_files("checkbox.js") ) From 366a14c05ff47b9b37635f8bfdca4c1aa6a9ba89 Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Mon, 18 Mar 2024 13:15:42 +0100 Subject: [PATCH 2/3] use restoreInput in update functions --- R/adtteSpec.R | 5 ++--- R/geneSpec.R | 2 +- R/pca.R | 8 +++----- R/quality.R | 15 ++++++--------- R/sampleVarSpec.R | 5 ++--- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/R/adtteSpec.R b/R/adtteSpec.R index ffda0b61..eb4fa70c 100644 --- a/R/adtteSpec.R +++ b/R/adtteSpec.R @@ -328,12 +328,11 @@ adtteSpecServer <- function(id, # nolint updateSelectizeInput( "paramcd", choices = paramcd_choices, - selected = new_selected, - session = session + selected = restoreInput(ns("paramcd"), new_selected) ) session$sendCustomMessage( "toggle_dropdown", - list(input_id = session$ns("paramcd"), disabled = (length(paramcd_choices) == 0)) + list(input_id = ns("paramcd"), disabled = (length(paramcd_choices) == 0)) ) }) diff --git a/R/geneSpec.R b/R/geneSpec.R index 1552302f..c2389c11 100644 --- a/R/geneSpec.R +++ b/R/geneSpec.R @@ -156,8 +156,8 @@ h_update_gene_selection <- function(session, updateSelectizeInput( session = session, inputId = inputId, - selected = selected[is_new_selected], choices = stats::setNames(choices$id, choices$name), + selected = restoreInput(session$ns(inputId), selected[is_new_selected]), server = TRUE ) diff --git a/R/pca.R b/R/pca.R index 125999d0..0f3075af 100644 --- a/R/pca.R +++ b/R/pca.R @@ -196,9 +196,8 @@ srv_g_pca <- function(id, if (filter_top) { n_top <- input$n_top updateSliderInput( - session = session, inputId = "n_top", - value = min(n_top, n_genes), + value = restoreInput(ns("n_top"), min(n_top, n_genes)), max = n_genes ) } @@ -233,10 +232,9 @@ srv_g_pca <- function(id, id_names <- c("x_var", "y_var") for (i in seq_along(id_names)) { updateSelectizeInput( - session, - id_names[i], + inputId = id_names[i], choices = pc_choices, - selected = pc_choices[i] + selected = restoreInput(ns(id_names[i]), pc_choices[i]) ) } }) diff --git a/R/quality.R b/R/quality.R index 234f3cd6..1b6ba666 100644 --- a/R/quality.R +++ b/R/quality.R @@ -244,24 +244,21 @@ srv_g_quality <- function(id, properties <- experiment_properties() teal.widgets::updateOptionalSelectInput( - session, - "annotate", + inputId = "annotate", choices = properties$annotations, - selected = "WidthBP" + selected = restoreInput(ns("annotate"), "WidthBP") ) updateSliderInput( - session, - "min_cpm", + inputId = "min_cpm", min = properties$min_cpm_calc, max = properties$max_cpm_calc, - value = properties$min_cpm_calc + value = restoreInput(ns("min_cpm"), properties$min_cpm_calc) ) updateSliderInput( - session, - "min_depth_continuous", + inputId = "min_depth_continuous", min = properties$min_depth_calc, max = properties$max_depth_calc, - value = properties$min_depth_calc + value = restoreInput(ns("min_depth_continuous"), properties$min_depth_calc) ) }) diff --git a/R/sampleVarSpec.R b/R/sampleVarSpec.R index 8712a2f2..c5f4f6a8 100644 --- a/R/sampleVarSpec.R +++ b/R/sampleVarSpec.R @@ -322,10 +322,9 @@ sampleVarSpecServer <- function(id, # nolint sel <- intersect(input$sample_var, col_data_vars) teal.widgets::updateOptionalSelectInput( - session, - "sample_var", + inputId = "sample_var", choices = col_data_vars, - selected = sel + selected = restoreInput(ns("sample_var"), sel) ) }) From abd7d71c8487015d3baafecfbd634c5c3c35e0c5 Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Mon, 18 Mar 2024 13:19:36 +0100 Subject: [PATCH 3/3] update for cosistency --- R/assaySpec.R | 4 +++- R/barplot.R | 4 +++- R/boxplot.R | 4 +++- R/forestplot.R | 4 +++- R/geneSpec.R | 6 ++++-- R/km.R | 4 +++- R/scatterplot.R | 4 +++- R/volcanoplot.R | 4 +++- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/R/assaySpec.R b/R/assaySpec.R index d798fc90..a7aa6784 100644 --- a/R/assaySpec.R +++ b/R/assaySpec.R @@ -106,6 +106,8 @@ assaySpecServer <- function(id, # nolint assert_character(exclude_assays, any.missing = FALSE) moduleServer(id, function(input, output, session) { + ns <- session$ns + # When the assay names change, update the choices for assay. choices <- reactive({ assays <- assays() @@ -131,7 +133,7 @@ assaySpecServer <- function(id, # nolint updateSelectizeInput(session, "name", choices = choices) session$sendCustomMessage( "toggle_dropdown", - list(input_id = session$ns("name"), disabled = (length(choices) == 0)) + list(input_id = ns("name"), disabled = (length(choices) == 0)) ) }) diff --git a/R/barplot.R b/R/barplot.R index a221827e..b3067fe7 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -122,8 +122,10 @@ srv_g_barplot <- function(id, checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/boxplot.R b/R/boxplot.R index bdccb1db..c0f8f1c9 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -119,8 +119,10 @@ srv_g_boxplot <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/forestplot.R b/R/forestplot.R index 36ce927b..1e94aafd 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -146,8 +146,10 @@ srv_g_forest_tte <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/geneSpec.R b/R/geneSpec.R index c2389c11..eb3143a2 100644 --- a/R/geneSpec.R +++ b/R/geneSpec.R @@ -300,6 +300,8 @@ geneSpecServer <- function(id, # nolint assert_character(label_modal_footer) moduleServer(id, function(input, output, session) { + ns <- session$ns + # The `reactiveValues` object for storing current gene text input. # This will also be a data frame with id and name columns. parsed_genes <- reactiveVal(NULL, label = "Parsed genes") @@ -380,14 +382,14 @@ geneSpecServer <- function(id, # nolint dataModal <- function(example_list) { # nolint modalDialog( textInput( - session$ns("gene_text"), + ns("gene_text"), label = label_modal_title, placeholder = example_list ), do.call("span", as.list(label_modal_footer)), footer = tagList( modalButton("Cancel"), - actionButton(session$ns("ok_button"), "OK") + actionButton(ns("ok_button"), "OK") ) ) } diff --git a/R/km.R b/R/km.R index 9f72906e..2ad07b61 100644 --- a/R/km.R +++ b/R/km.R @@ -151,8 +151,10 @@ srv_g_km <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/scatterplot.R b/R/scatterplot.R index 2004144c..563ee5b4 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -122,8 +122,10 @@ srv_g_scatterplot <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment <- experimentSpecServer( "experiment", diff --git a/R/volcanoplot.R b/R/volcanoplot.R index 217ac1a0..3df0ab83 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -110,8 +110,10 @@ srv_g_volcanoplot <- function(id, checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + ns <- session$ns + output$experiment_ui <- renderUI({ - experimentSpecInput(session$ns("experiment"), data, mae_name) + experimentSpecInput(ns("experiment"), data, mae_name) }) experiment_data <- experimentSpecServer( "experiment",