From 3c31e1ab5f43a622e72d0e07ea5b819fc4aea123 Mon Sep 17 00:00:00 2001 From: James Bisese Date: Wed, 4 Dec 2024 13:04:33 -0500 Subject: [PATCH 1/9] Download Template #84 Added UI element and server code to download a TADA template in excel format --- R/mod_query_data.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index f5b716bb..73ce1567 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -222,6 +222,20 @@ mod_query_data_ui <- function(id) { ) ) ), + shiny::fluidRow( + htmltools::HTML( + "Download a TDATA dataset template in .xlsx format. This download template can be used to prepare datasets for Upload. + You may reach out to the WQX helpdesk at WQX@epa.gov for assistance preparing and submitting your data + to the WQP through EPA's WQX.

" + ), + column( + 9, + shiny::downloadButton( + ns("download_template"), + "Download Template", + style = "color: #fff; background-color: #337ab7; border-color: #2e6da4;") + ) + ), htmltools::hr(), shiny::fluidRow( htmltools::h3("Optional: Upload Progress File"), @@ -256,6 +270,26 @@ mod_query_data_server <- function(id, tadat) { shiny::moduleServer(id, function(input, output, session) { ns <- session$ns + + # template used for importing data to TADAShiny + template_data <- reactive(EPATADA::TADA_GetTemplate()) + + # return an ms excel file with the template columns + output$download_template <- shiny::downloadHandler( + filename = function() { + paste0("tada_template", ".xlsx") + }, + content = function(file) { + # format csv. contentType = "text/csv" + # write.csv(template_data(), file) + # browser() + # format excel (xlsx) + d = template_data() + writexl::write_xlsx(d, path = file) + }, + contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + ) + # 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 decf2797fecf984642a6478c9544e07ccdcccd55 Mon Sep 17 00:00:00 2001 From: James Bisese Date: Wed, 4 Dec 2024 13:19:03 -0500 Subject: [PATCH 2/9] 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 84d415cbef71a158b777c6b51a847b9f5fe86010 Mon Sep 17 00:00:00 2001 From: James Bisese Date: Wed, 4 Dec 2024 13:33:59 -0500 Subject: [PATCH 3/9] providers as a filter option on import tab #129 Add Providers (EPA/NWIS) as a filter option on import tab #129. And create a 'Select Both' option, and do not allow a Select None option --- R/mod_query_data.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index f5b716bb..c9fafc84 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -188,10 +188,9 @@ mod_query_data_ui <- function(id) { shiny::fluidRow( column( 4, - shiny::checkboxGroupInput(ns("providers"), + shiny::radioButtons(ns("providers"), "Data Source", - c("NWIS (USGS)" = "NWIS", "WQX (EPA)" = "STORET"), - selected = c("NWIS", "STORET")) + c("NWIS (USGS)" = "NWIS", "WQX (EPA)" = "STORET", "Both (NWIS and WQX)" = "all"), selected = "all") ) ), shiny::fluidRow(column( @@ -402,7 +401,7 @@ mod_query_data_server <- function(id, tadat) { } else { tadat$countrycode <- input$countryocean } - if (is.null(input$providers)) { + if (is.null(input$providers) | input$providers == "all") { tadat$providers <- "null" } else { tadat$providers <- input$providers From 4cd24e4ae8507a64821988253e163d3807a0133d Mon Sep 17 00:00:00 2001 From: James Bisese Date: Wed, 4 Dec 2024 16:56:06 -0500 Subject: [PATCH 4/9] 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 5/9] 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 6/9] 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" From 81641d8498754827a2ee3dd8c47e3f284d266b0b Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:58:33 -0500 Subject: [PATCH 7/9] update wording for Option C on import tab --- R/mod_query_data.R | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index 73ce1567..2b2b7947 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -204,11 +204,9 @@ mod_query_data_ui <- function(id) { shiny::fluidRow( htmltools::h3("Option C: Upload dataset"), htmltools::HTML(( - "Upload a dataset from your computer. This upload feature only accepts data in .xls and .xlsx formats. - The file can be a fresh TADA dataset or a working TADA dataset that you are returning to the - app to iterate on. Data must also be formatted in the EPA Water Quality eXchange (WQX) schema to leverage - this tool. You may reach out to the WQX helpdesk at WQX@epa.gov for assistance preparing and submitting your data - to the WQP through EPA's WQX." + "Upload a compatible dataset from your computer. This upload feature only accepts data in .xls and .xlsx formats. Data must be formatted in the EPA Water Quality eXchange (WQX) schema (and include all columns required for this TADA R Shiny application) to run + this tool. The file can be a fresh dataset you created using the TADA template below or a working dataset that you downloaded from this application using the Download Working Dataset feature, and are now returning to the + app to iterate on." )), # widget to upload WQP profile or WQX formatted spreadsheet column( @@ -224,9 +222,9 @@ mod_query_data_ui <- function(id) { ), shiny::fluidRow( htmltools::HTML( - "Download a TDATA dataset template in .xlsx format. This download template can be used to prepare datasets for Upload. - You may reach out to the WQX helpdesk at WQX@epa.gov for assistance preparing and submitting your data - to the WQP through EPA's WQX.

" + "Download a blank TADA data template in .xlsx format. This template is available to assist users that do not have data available in the WQP (and therefore cannot use Option B) prepare their data for upload to this R Shiny application using import Option C. + You may reach out to the TADA team through the helpdesk at mywaterway@epa.gov for assistance preparing your data. If your data is not in the WQP yet and you are interested in submitting it, you may reach out to the WQX helpdesk at WQX@epa.gov for assistance preparing and submitting your data + to the WQP through EPA's WQX.

" ), column( 9, From e422422d4e443c2ac92247b05d584e5d75407b03 Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:37:08 -0500 Subject: [PATCH 8/9] allow multiple projects on import tab --- R/mod_query_data.R | 2 +- R/utils_track_progress.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index 05226ab5..6a5fae41 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -447,7 +447,7 @@ mod_query_data_server <- function(id, tadat) { if (is.null(input$project)) { tadat$project <- "null" } else { - tadat$project <- paste(input$project, collapse = ",") + tadat$project <- input$project } if (is.null(input$org)) { tadat$organization <- "null" diff --git a/R/utils_track_progress.R b/R/utils_track_progress.R index 8f6c92ab..7e30dc21 100644 --- a/R/utils_track_progress.R +++ b/R/utils_track_progress.R @@ -112,6 +112,7 @@ writeNarrativeDataFrame <- function(tadat) { tadat$siteType <- paste(tadat$siteType, collapse = " ") tadat$characteristicType <- paste(tadat$characteristicType, collapse = " ") tadat$characteristicName <- paste(tadat$characteristicName, collapse = " ") + tadat$project <- paste(tadat$project, collapse = " ") df <- data.frame(Parameter = character(), Value = character()) df[nrow(df) + 1, ] <- c("TADA Shiny Job ID", tadat$job_id) df[nrow(df) + 1, ] <- c("Original data source: ", tadat$original_source) From 485e9fc680e2bc923f62a2208f047e6f88f58747 Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:16:28 -0500 Subject: [PATCH 9/9] add notes --- R/mod_query_data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/mod_query_data.R b/R/mod_query_data.R index a18a92f6..00da3d4a 100644 --- a/R/mod_query_data.R +++ b/R/mod_query_data.R @@ -268,9 +268,8 @@ mod_query_data_server <- function(id, tadat) { shiny::moduleServer(id, function(input, output, session) { ns <- session$ns - # template used for importing data to TADAShiny + ## creates download template button used for importing data to TADAShiny - used in option C template_data <- reactive(EPATADA::TADA_GetTemplate()) - # return an ms excel file with the template columns output$download_template <- shiny::downloadHandler( filename = function() { @@ -287,6 +286,7 @@ mod_query_data_server <- function(id, tadat) { contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) + ## greys out Load button for example data until file has been selected # 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) {