Skip to content

Commit

Permalink
Merge pull request #134 from USEPA/review_fix
Browse files Browse the repository at this point in the history
Review fix
  • Loading branch information
cristinamullin authored Feb 23, 2024
2 parents 6edb886 + 3c076ef commit 516cf03
Show file tree
Hide file tree
Showing 18 changed files with 14,918 additions and 260 deletions.
55 changes: 28 additions & 27 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
Package: TADAShiny
Type: Package
Title: WQP Data Discovery and Cleaning: First R Shiny App in the TADA (Tools for Automated Data Analysis) Series
Title: Water Quality Portal Data Discovery and Cleaning: First R Shiny App in the TADA (Tools for Automated Data Analysis) Series
Version: 0.0.0.9000
Organization: U.S. Environmental Protection Agency
Authors@R:
c(person(given = "Cristina",
family = "Mullin",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-0615-6087")),
person(given = "Trip",
family = "Hook",
role = "aut"),
person(given = "Elise",
family = "Hinman",
role = c("aut"),
email = "[email protected]"),
person(given = "Hui",
family = "Zhou",
role = c("aut"),
email = "[email protected]"),
person(given = "Shelly",
family = "Thawley",
role = "aut"))
Description: Assists data partners in retrieving, wrangling, quality checking, and preparing data from the Water Quality Portal for subsequent analyses.
Authors@R: c(
person(given = "U.S. Environmental Protection Agency", role = "aut"),
person(given = "Cristina",
family = "Mullin",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-0615-6087")),
person(given = "Trip",
family = "Hook",
role = "aut"),
person(given = "Elise",
family = "Hinman",
role = "aut"),
person(given = "Hillary",
family = "Marler",
role = "aut"),
person(given = "Shelly",
family = "Thawley",
role = "aut"),
person(given = "Hui",
family = "Zhou",
role = "aut")
)
Description: Assists data partners in retrieving, wrangling, quality checking, and harmonizing data from the Water Quality Portal for subsequent analyses.
License: CC0
Copyright: This software is in the public domain because it contains materials
that originally came from the U.S. Environmental Protection Agency.
Imports:
config,
golem,
magrittr,
golem,
htmltools,
readxl,
writexl,
Expand All @@ -54,6 +55,7 @@ Imports:
Remotes:
github::USEPA/TADA
Suggests:
config,
testthat,
remotes,
covr,
Expand All @@ -73,6 +75,5 @@ Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)
LazyData: true
URL: https://github.com/USEPA/TADAShiny
BugReports: https://github.com/USEPA/TADAShiny/issues
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr, rmarkdown
36 changes: 17 additions & 19 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Below increases the max data upload size from the Shiny default of 5MB per file
# to 30MB for file
options(shiny.maxRequestSize = 30 * 1024^2)

options(warn = 2)
app_server <- function(input, output, session) {
# Your application server logic
tadat <- shiny::reactiveValues() # create a list object that holds reactive values passed between modules
Expand All @@ -35,6 +35,7 @@ app_server <- function(input, output, session) {
# switch that indicates when a file is being loaded
tadat$load_progress_file = NA
tadat$save_progress_file = NA
tadat$flags_present = FALSE
job_id = paste0("ts", format(Sys.time(), "%y%m%d%H%M%S"))
tadat$default_outfile = paste0("tada_output_", job_id)
tadat$job_id = job_id
Expand All @@ -44,7 +45,7 @@ app_server <- function(input, output, session) {
shiny::observeEvent(tadat$new, {
shiny::showModal(shiny::modalDialog(
title = "Data Loaded",
"Your data were successfully loaded into the app and are displayed on the Overview tab. The following data wrangling steps were performed automatically when data was loaded: 1) created TADA versions of a subset of columns for editing (originals are retained), 2) removed exact duplicates, 3) handled/flagged special characters and text in result values and units, 4) identified detection limit data and copied limit value to result value if blank, 5) harmonized result and depth units to TADA defaults, and 6) replaced retired characteristic names with current names. See summary information about your dataset in the gray box at the bottom of the app."
"Your data were successfully loaded into the app and are displayed on the Overview tab. The following data wrangling steps were performed automatically when data was loaded: 1) created TADA versions of a subset of columns for editing (originals are retained), 2) handled/flagged special characters and text in result values and units, 3) harmonized result and depth units to TADA defaults, and 4) replaced retired characteristic names with current names. See summary information about your dataset in the gray box at the bottom of the app."
))
shiny::updateTabsetPanel(session = session, inputId = "tabbar", selected = "Overview")
tadat$new <- NULL
Expand All @@ -57,27 +58,24 @@ app_server <- function(input, output, session) {
}
})

# Update the default switches if a progress file is uploaded.
shiny::observeEvent(tadat$selected_flags, {
switch_defaults = tadat$selected_flags
})


# this observes when the user switches tabs and adds the current tab they're on as a column to their dataset.
shiny::observe({
shiny::req(tadat$raw)
# JCH - is this necessary?
#shiny::req(tadat$raw)
tadat$raw$TADAShiny.tab <- input$tabbar
tadat$tab <- input$tabbar
})

# JCH - disabling this for now. I think progress files provide this functionality
# this observes when the user switches tabs and adds the current tab they're on as a column to their dataset.

# switch to tab user left off on when tadat$reup changes, which only happens when someone uploads a workbook with the column "Removed" in it
shiny::observeEvent(tadat$reup, {
shiny::showModal(shiny::modalDialog(
title = "Data Loaded",
"Your working dataset has been uploaded and the app switched to the tab where you left off."
))
# the switch tab command
shiny::updateTabsetPanel(session = session, inputId = "tabbar", selected = unique(tadat$raw$tab))
tadat$reup <- NULL
})
#shiny::observeEvent(tadat$reup, {
# shiny::showModal(shiny::modalDialog(
# title = "Data Loaded",
# "Your working dataset has been uploaded and the app switched to the tab where you left off."
# ))
# # the switch tab command
# shiny::updateTabsetPanel(session = session, inputId = "tabbar", selected = unique(tadat$raw$tab))
# tadat$reup <- NULL
#})
}
61 changes: 38 additions & 23 deletions R/mod_TADA_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ mod_TADA_summary_ui <- function(id) {
"site_clean"
)))),
shiny::fluidRow(column(6, shiny::uiOutput(ns(
"dwn_all"
"dwn_working"
)))),
shiny::fluidRow(column(6, shiny::uiOutput(ns(
"dwn_ts"
"dwn_final"
))))#,
# shiny::fluidRow(column(
# 6,
Expand Down Expand Up @@ -169,16 +169,25 @@ mod_TADA_summary_server <- function(id, tadat) {
})

# download dataset button - only appears if there data exists in the app already
output$dwn_all <- shiny::renderUI({
output$dwn_working <- shiny::renderUI({
shiny::req(tadat$raw)
shiny::downloadButton(ns("download_all"),
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",
contentType = "application/zip")
})

output$download_all <- shiny::downloadHandler(
output$dwn_final <- shiny::renderUI({
shiny::req(tadat$raw)
shiny::downloadButton(ns("download_final"),
"Download Final Dataset (.zip)",
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4",
contentType = "application/zip")
})

output$download_working <- shiny::downloadHandler(
filename = function() {
paste0(tadat$default_outfile, ".zip")
paste0(tadat$default_outfile, "_working.zip")
},
content = function(fname) {
fs <- c()
Expand All @@ -197,22 +206,28 @@ mod_TADA_summary_server <- function(id, tadat) {
contentType = "application/zip"
)

# # Download TADA progress file
# output$dwn_ts = shiny::renderUI({
# shiny::req(tadat$raw)
# shiny::downloadButton(ns("download_ts_file"),
# "Download Progress File (.Rdata)",
# style = "color: #fff; background-color: #337ab7; border-color: #2e6da4")
# })

# output$download_ts_file = shiny::downloadHandler(
# filename = function() {
# paste0(tadat$job_id, '.Rdata')
# },
# content = function(file) {
# writeFile(tadat, file)
# }
# )
output$download_final <- shiny::downloadHandler(
filename = function() {
paste0(tadat$default_outfile, "_final.zip")
},
content = function(fname) {
fs <- c()
tmpdir <- tempdir()
setwd(tempdir())
datafile_name = paste0(tadat$default_outfile, ".xlsx")
progress_file_name = paste0(tadat$default_outfile, "_prog.RData")
desc <- writeNarrativeDataFrame(tadat)

# Remove all rows flagged for removal
dfs <-
list(Data = TADA::TADA_OrderCols(tadat$raw[!tadat$raw$TADA.Remove,]), Parameterization = desc)
writeFile(tadat, progress_file_name)
writexl::write_xlsx(dfs, path = datafile_name)
utils::zip(zipfile = fname,
files = c(datafile_name, progress_file_name))
},
contentType = "application/zip"
)

shiny::observeEvent(input$disclaimer, {
shiny::showModal(
Expand Down
Loading

0 comments on commit 516cf03

Please sign in to comment.