From decf2797fecf984642a6478c9544e07ccdcccd55 Mon Sep 17 00:00:00 2001 From: James Bisese Date: Wed, 4 Dec 2024 13:19:03 -0500 Subject: [PATCH 1/4] Disable Load button until option selected Prevent fatal error by disabling Load button on Load tab until the user has selected an Example dataset. --- R/mod_query_data.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index f5b716bb..e5867ad9 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -58,6 +58,7 @@ mod_query_data_ui <- function(id) { ns("example_data_go"), "Load", shiny::icon("truck-ramp-box"), + disabled = TRUE, style = "color: #fff; background-color: #337ab7; border-color: #2e6da4" ) )), @@ -256,6 +257,13 @@ mod_query_data_server <- function(id, tadat) { shiny::moduleServer(id, function(input, output, session) { ns <- session$ns + # https://stackoverflow.com/questions/24175997/force-no-default-selection-in-selectinput + shiny::observeEvent(input$example_data, { + if (!is.na(input$example_data) && nchar(input$example_data) > 1) { + shinyjs::enable("example_data_go") + } + }) + # read in the excel spreadsheet dataset if this input reactive object is populated via fileInput and define as tadat$raw shiny::observeEvent(input$file, { # a modal that pops up showing it's working on querying the portal From 4cd24e4ae8507a64821988253e163d3807a0133d Mon Sep 17 00:00:00 2001 From: James Bisese Date: Wed, 4 Dec 2024 16:56:06 -0500 Subject: [PATCH 2/4] Disable Apply Methods to Dataset button Added logic to disable Apply Methods to Dataset button when the inputs are not complete or the button is not useful. --- R/mod_censored_data.R | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/R/mod_censored_data.R b/R/mod_censored_data.R index effba121..68edec35 100644 --- a/R/mod_censored_data.R +++ b/R/mod_censored_data.R @@ -64,7 +64,11 @@ mod_censored_data_ui <- function(id) { shiny::fluidRow( column( 3, - shiny::actionButton(ns("apply_methods"), "Apply Methods to Dataset", style = "color: #fff; background-color: #337ab7; border-color: #2e6da4") + shiny::actionButton( + ns("apply_methods"), + "Apply Methods to Dataset", + disabled = TRUE, + style = "color: #fff; background-color: #337ab7; border-color: #2e6da4") ), column(3, shiny::uiOutput(ns("undo_methods"))) ), @@ -99,7 +103,7 @@ mod_censored_data_ui <- function(id) { mod_censored_data_server <- function(id, tadat) { shiny::moduleServer(id, function(input, output, session) { ns <- session$ns - + # initialize dropdown values # reactive values specific to this module @@ -162,9 +166,9 @@ mod_censored_data_server <- function(id, tadat) { if (is.null(init_val)) { init_val <- 0.5 } - if (input$nd_method == nd_method_options[1]) { + if (input$nd_method == "Multiply detection limit by x") { shiny::numericInput(ns("nd_mult"), - "Multiplier (x)", + "Non-Detect Multiplier (x)", value = init_val, min = 0 ) @@ -177,9 +181,9 @@ mod_censored_data_server <- function(id, tadat) { if (is.null(init_val)) { init_val <- 0.5 } - if (input$od_method == od_method_options[1]) { + if (input$od_method == "Multiply detection limit by x") { shiny::numericInput(ns("od_mult"), - "Multiplier (x)", + "Over-Detect Multiplier (x)", value = init_val, min = 0 ) @@ -211,18 +215,44 @@ mod_censored_data_server <- function(id, tadat) { # Make this part more concise? shiny::observeEvent(input$nd_method, { tadat$nd_method <- input$nd_method + + if ((input$nd_method == "Multiply detection limit by x" && !is.numeric(input$nd_mult)) + || (input$nd_method == "No change" && input$od_method == "No change" )){ + shinyjs::disable("apply_methods") + } else { + shinyjs::enable("apply_methods") + } }) shiny::observeEvent(input$nd_mult, { tadat$nd_mult <- input$nd_mult + + if (input$nd_method == "Multiply detection limit by x" && !is.numeric(input$nd_mult)) { + shinyjs::disable("apply_methods") + } else { + shinyjs::enable("apply_methods") + } }) shiny::observeEvent(input$od_method, { tadat$od_method <- input$od_method + + if ((input$od_method == "Multiply detection limit by x" && !is.numeric(input$od_mult)) + || (input$nd_method == "No change" && input$od_method == "No change" )){ + shinyjs::disable("apply_methods") + } else { + shinyjs::enable("apply_methods") + } }) shiny::observeEvent(input$od_mult, { tadat$od_mult <- input$od_mult + + if (input$od_method == "Multiply detection limit by x" && !is.numeric(input$od_mult)) { + shinyjs::disable("apply_methods") + } else { + shinyjs::enable("apply_methods") + } }) From 66aafc544400c9c3b6434f8a7b4701e51ed39ed9 Mon Sep 17 00:00:00 2001 From: James Bisese Date: Thu, 5 Dec 2024 12:07:32 -0500 Subject: [PATCH 3/4] toggle Apply Methods to Dataset button Disable "Apply Methods to Dataset" button on Censored Data tab if no Multiplier (x) is provided --- R/mod_TADA_summary.R | 2 +- R/mod_censored_data.R | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/R/mod_TADA_summary.R b/R/mod_TADA_summary.R index 5f8127e5..2e5ae8e8 100644 --- a/R/mod_TADA_summary.R +++ b/R/mod_TADA_summary.R @@ -181,7 +181,7 @@ mod_TADA_summary_server <- function(id, tadat) { shiny::req(tadat$raw) shiny::downloadButton(ns("download_working"), "Download Working Dataset (.zip)", - style = "color: #fff; background-color: #337ab7; border-color: #2e6da4", + style = "color: #fff; background-color: #337ab7; border-color: #2e6da4; margin-bottom: 10px;", contentType = "application/zip" ) }) diff --git a/R/mod_censored_data.R b/R/mod_censored_data.R index 68edec35..0d8e1b87 100644 --- a/R/mod_censored_data.R +++ b/R/mod_censored_data.R @@ -322,6 +322,13 @@ mod_censored_data_server <- function(id, tadat) { dat[1:10, ] # just show the first 10 records so user can see what happened to data shinybusy::remove_modal_spinner(session = shiny::getDefaultReactiveDomain()) tadat$censor_applied <- TRUE + + # disable the button so the user can not redo the handling + shinyjs::disable("apply_methods") + shinyjs::disable("nd_mult") + shinyjs::disable("nd_method") + shinyjs::disable("od_mult") + shinyjs::disable("od_method") }) # this button appears after someone has applied the OD/ND methods, in case they want to undo and try another method instead @@ -343,6 +350,13 @@ mod_censored_data_server <- function(id, tadat) { "Result Value/Unit Copied from Detection Limit" # reset data types flag to what it was before simpleCensoredMethods function run tadat$raw <- tadat$raw %>% dplyr::select(-TADA.CensoredMethod) tadat$censor_applied <- FALSE + + # enable the button so the user can re-apply the handling + shinyjs::enable("apply_methods") + shinyjs::enable("nd_mult") + shinyjs::enable("nd_method") + shinyjs::enable("od_mult") + shinyjs::enable("od_method") }) # creates a nice table showing an example of how censored data were changed. From bd499661c8af672a643495250c9b7d346ae382ef Mon Sep 17 00:00:00 2001 From: James Bisese Date: Thu, 5 Dec 2024 12:40:39 -0500 Subject: [PATCH 4/4] remove spaces from HUC input field Remove any spaces included in user input in the HUC field. This prevents fatal error during query --- R/mod_query_data.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index e5867ad9..f64a0e73 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -418,7 +418,7 @@ mod_query_data_server <- function(id, tadat) { if (input$huc == "") { tadat$huc <- "null" } else { - tadat$huc <- input$huc + tadat$huc <- gsub("\\s", "", input$huc) } if (is.null(input$siteid)) { tadat$siteid <- "null"