Skip to content

Commit

Permalink
Merge branch 'download-template-84' into fix-option-C-#135
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinamullin committed Dec 12, 2024
2 parents 350e769 + 485e9fc commit c650cff
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/mod_TADA_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
})
Expand Down
56 changes: 50 additions & 6 deletions R/mod_censored_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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")
}
})


Expand Down Expand Up @@ -292,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
Expand All @@ -313,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.
Expand Down
60 changes: 49 additions & 11 deletions R/mod_query_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)),
Expand Down Expand Up @@ -188,10 +189,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(
Expand All @@ -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 <B>fresh</B> TADA dataset or a <B>working</B> 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 [email protected] 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 <B>fresh</B> dataset you created using the TADA template below or a <B>working</B> 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(
Expand All @@ -222,6 +220,20 @@ mod_query_data_ui <- function(id) {
)
)
),
shiny::fluidRow(
htmltools::HTML(
"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 [email protected] 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 [email protected] for assistance preparing and submitting your data
to the WQP through EPA's WQX.<br><br>"
),
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"),
Expand Down Expand Up @@ -255,6 +267,32 @@ mod_query_data_ui <- function(id) {
mod_query_data_server <- function(id, tadat) {
shiny::moduleServer(id, function(input, output, session) {
ns <- session$ns

## 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() {
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"
)

## 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) {
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, {
Expand Down Expand Up @@ -413,15 +451,15 @@ 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
}
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"
Expand Down Expand Up @@ -451,7 +489,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"
Expand Down
1 change: 1 addition & 0 deletions R/utils_track_progress.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c650cff

Please sign in to comment.