From d2d1e09858de663b6ba5eebac55696ff205490d6 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Fri, 19 Nov 2021 15:38:46 +0100 Subject: [PATCH] Move optimization to preset editor --- R/methods.R | 65 ++++++++++++++++++----------------------------- R/preset_editor.R | 15 +++++++++-- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/R/methods.R b/R/methods.R index cb7ab2c..4daa723 100644 --- a/R/methods.R +++ b/R/methods.R @@ -23,18 +23,9 @@ methods_ui <- function(id) { ) ) }), - radioButtons( - NS(id, "target"), - "Optimization target", - choices = list( - "Mean rank of reference genes" = "mean", - "First rank of reference genes" = "min", - "Last rank of reference genes" = "max" - ) - ), actionButton( - NS(id, "optimize_button"), - "Optimize weights", + NS(id, "reset_button"), + "Reset weights", class = "btn-primary" ) ) @@ -47,33 +38,6 @@ methods_ui <- function(id) { # @return A reactive containing the weighted results. methods_server <- function(id, analysis) { moduleServer(id, function(input, output, session) { - observeEvent(input$optimize_button, { - analysis <- analysis() - method_ids <- NULL - - # Only include activated methods. - for (method in methods) { - if (input[[method$id]]) { - method_ids <- c(method_ids, method$id) - } - } - - weights <- geposan::optimal_weights( - analysis, - method_ids, - analysis$preset$reference_gene_ids, - target = input$target - ) - - for (method_id in method_ids) { - updateSliderInput( - session, - sprintf("%s_weight", method_id), - value = weights[[method_id]] - ) - } - }) - # Observe each method's enable button and synchronise the slider state. lapply(methods, function(method) { observeEvent(input[[method$id]], @@ -84,9 +48,30 @@ methods_server <- function(id, analysis) { ) }) - reactive({ - # Take the actual weights from the sliders. + observeEvent( + { # nolint + analysis() + input$reset_button + }, + { # nolint + for (method in methods) { + updateCheckboxInput( + session, + method$id, + value = TRUE + ) + updateSliderInput( + session, + sprintf("%s_weight", method$id), + value = analysis()$weights[[method$id]] + ) + } + }, + ignoreNULL = FALSE + ) + + reactive({ weights <- NULL for (method in methods) { diff --git a/R/preset_editor.R b/R/preset_editor.R index 72f2059..acc4eee 100644 --- a/R/preset_editor.R +++ b/R/preset_editor.R @@ -61,6 +61,15 @@ preset_editor_ui <- function(id) { ) ) ), + selectInput( + NS(id, "optimization_target"), + "Optimization target", + choices = list( + "Mean rank of reference genes" = "mean", + "First rank of reference genes" = "min", + "Last rank of reference genes" = "max" + ) + ), tabsetPanel( id = NS(id, "apply_panel"), type = "hidden", @@ -89,7 +98,8 @@ preset_editor_server <- function(id) { methods = method_ids, species_ids = species[replicative == TRUE, id], gene_ids = genes$id, - reference_gene_ids = genes[suggested | verified == TRUE, id] + reference_gene_ids = genes[suggested | verified == TRUE, id], + optimization_target = "mean" )) observeEvent(input$species, { @@ -145,7 +155,8 @@ preset_editor_server <- function(id) { methods = method_ids, species_ids = species_ids, gene_ids = genes$id, - reference_gene_ids = reference_gene_ids + reference_gene_ids = reference_gene_ids, + optimization_target = input$optimization_target ) })