Skip to content

Commit

Permalink
Merge pull request #162 from USEPA/cm-release-review-2
Browse files Browse the repository at this point in the history
Cm release review 2
  • Loading branch information
cristinamullin authored Jun 12, 2024
2 parents 23a7fff + 96413be commit 48b7259
Show file tree
Hide file tree
Showing 22 changed files with 579 additions and 507 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Shiny/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/rocker-org/devcontainer/geospatial:4",
"features": {
"ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
"packages": "github::USEPA/TADA,config,golem,readxl,writexl,leaflet,shiny,shinyWidgets,shinyjs,shinycssloaders,DT,ggplot2,shinybusy,dplyr,plyr,tidyr,scales,forcats,RColorBrewer,lubridate,plotly",
"packages": "github::USEPA/EPATADA,config,golem,readxl,writexl,leaflet,shiny,shinyWidgets,shinyjs,shinycssloaders,DT,ggplot2,shinybusy,dplyr,plyr,tidyr,scales,forcats,RColorBrewer,lubridate,plotly",
"installSystemRequirements": true
}
},
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"image": "ghcr.io/rocker-org/devcontainer/geospatial:4",
"features": {
"ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
"packages": "github::USEPA/TADA,config,golem,readxl,writexl,leaflet,shiny,shinyWidgets,shinyjs,shinycssloaders,DT,ggplot2,shinybusy,dplyr,plyr,tidyr,scales,forcats,RColorBrewer,lubridate,plotly",
"packages": "github::USEPA/EPATADA,config,golem,readxl,writexl,leaflet,shiny,shinyWidgets,shinyjs,shinycssloaders,DT,ggplot2,shinybusy,dplyr,plyr,tidyr,scales,forcats,RColorBrewer,lubridate,plotly",
"installSystemRequirements": true
}
},
Expand Down
16 changes: 12 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ Add any other context about the problem here.

**Reminders for TADA contributors addressing this issue**

New features should include all of the following work:
Bug fixes should include the following work:

- [ ] Create the function/code.
- [ ] Create or edit the code.

- [ ] Document all code using comments to describe what is does.
- [ ] Document all code using line/inline and/or multi-line/block comments
to describe what is does.

- [ ] Create tests.
- [ ] Create or edit tests in tests/testthat folder to help prevent and/or
troubleshoot potential future issues.

- [ ] If your code edits impact other functionality in the shiny
app, ensure those are updated as well.

- [ ] Run styler::style_pkg(), devtools::document(), and devtools::check()
and address any new notes or issues before creating a pull request.
16 changes: 12 additions & 4 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ Add any other context or screenshots about the feature request here.

**Reminders for TADA contributors addressing this issue**

New features should include all of the following work:
New features and/or edits should include the following work:

- [ ] Create the function/code.
- [ ] Create or edit the code.

- [ ] Document all code using comments to describe what is does.
- [ ] Document all code using line/inline and/or multi-line/block comments
to describe what is does.

- [ ] Create tests.
- [ ] Create or edit tests in tests/testthat folder to help prevent and/or
troubleshoot potential future issues.

- [ ] If your code edits impact other functionality in the shiny
app, ensure those are updated as well.

- [ ] Run styler::style_pkg(), devtools::document(), and devtools::check()
and address any new notes or issues before creating a pull request.
13 changes: 2 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ Authors@R: c(
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.
Expand All @@ -41,7 +32,7 @@ Imports:
shinycssloaders,
DT,
ggplot2,
TADA,
EPATADA,
shinybusy,
dplyr,
plyr,
Expand All @@ -53,7 +44,7 @@ Imports:
lubridate,
plotly
Remotes:
github::USEPA/TADA
github::USEPA/EPATADA
Suggests:
config,
testthat,
Expand Down
22 changes: 11 additions & 11 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ app_server <- function(input, output, session) {
shinyjs::disable(selector = '.nav li a[data-value="Review"]')

# 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
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

# switch to overview tab when tadat$new changes and provide user with window letting them know how many records were automatically flagged for removal upon upload
# move this to query_data?
shiny::observeEvent(tadat$new, {
Expand All @@ -60,22 +60,22 @@ app_server <- function(input, output, session) {

shiny::observe({
# JCH - is this necessary?
#shiny::req(tadat$raw)
# 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::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
#})
# })
}
4 changes: 2 additions & 2 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ css <- "
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
# This function automatically incorporates the epa styles.css file included
# This function automatically incorporates the epa styles.css file included
# in the www folder. Downloaded from https://www.epa.gov/web-policies-and-procedures/web-standards-look-and-feel-template
# styles.css hosted locally in this app includes a fix (for compatibility with leaflet and plotly)
golem_add_external_resources(),
Expand Down Expand Up @@ -80,7 +80,7 @@ app_ui <- function(request) {
),
htmltools::hr(),
mod_TADA_summary_ui("TADA_summary_1"),
# adds epa footer html
# adds epa footer html
shiny::includeHTML(app_sys("app/www/footer.html"))
)
)
Expand Down
100 changes: 57 additions & 43 deletions R/mod_TADA_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod_TADA_summary_ui <- function(id) {
)))),
shiny::fluidRow(column(6, shiny::uiOutput(ns(
"dwn_final"
))))#,
)))) # ,
# shiny::fluidRow(column(
# 6,
# shiny::fileInput(
Expand Down Expand Up @@ -75,33 +75,33 @@ mod_TADA_summary_server <- function(id, tadat) {
shiny::moduleServer(id, function(input, output, session) {
ns <- session$ns
# reactive list to hold reactive objects specific to this module
summary_things = shiny::reactiveValues()
summary_things <- shiny::reactiveValues()


# calculate the stats needed to fill the summary box
shiny::observe({
shiny::req(tadat$raw)
summary_things$rem_rec <-
length(tadat$raw$ResultIdentifier[tadat$raw$TADA.Remove ==
TRUE])
TRUE])
summary_things$clean_rec <-
length(tadat$raw$ResultIdentifier[tadat$raw$TADA.Remove ==
FALSE])
FALSE])
clean_sites <-
unique(tadat$raw$MonitoringLocationIdentifier[tadat$raw$TADA.Remove ==
FALSE])
FALSE])
summary_things$clean_site <- length(clean_sites)
summary_things$rem_site <-
length(unique(tadat$raw$MonitoringLocationIdentifier[!tadat$raw$MonitoringLocationIdentifier %in%
clean_sites]))
clean_sites]))
summary_things$removals <- sort_removals(tadat$removals)
})
summary_things$removals <- data.frame(matrix(
ncol = 2,
nrow = 0,
dimnames = list(NULL, c("Reason", "Count"))
))

# output$removal_summary = DT::renderDataTable(
# summary_things$removals,
# escape = FALSE,
Expand All @@ -112,7 +112,7 @@ mod_TADA_summary_server <- function(id, tadat) {
# language = list(zeroRecords = "No records removed")
# )
# )

# summary text = total records
output$rec_tot <- shiny::renderText({
if (is.null(tadat$raw)) {
Expand All @@ -126,17 +126,21 @@ mod_TADA_summary_server <- function(id, tadat) {
if (is.null(tadat$raw)) {
"Total Results Flagged for Removal: 0"
} else {
paste0("Total Results Flagged for Removal: ",
scales::comma(summary_things$rem_rec))
paste0(
"Total Results Flagged for Removal: ",
scales::comma(summary_things$rem_rec)
)
}
})
# summary text = total records in clean
output$rec_clean <- shiny::renderText({
if (is.null(tadat$raw)) {
"Total Results Retained: 0"
} else {
paste0("Total Results Retained: ",
scales::comma(summary_things$clean_rec))
paste0(
"Total Results Retained: ",
scales::comma(summary_things$clean_rec)
)
}
})
# summary text = total sites
Expand All @@ -154,37 +158,43 @@ mod_TADA_summary_server <- function(id, tadat) {
if (is.null(tadat$raw)) {
"Total Sites Flagged for Removal: 0"
} else {
paste0("Total Sites Flagged for Removal: ",
scales::comma(summary_things$rem_site))
paste0(
"Total Sites Flagged for Removal: ",
scales::comma(summary_things$rem_site)
)
}
})
# summary text = total sites in clean file
output$site_clean <- shiny::renderText({
if (is.null(tadat$raw)) {
"Total Sites Retained: 0"
} else {
paste0("Total Sites Retained: ",
scales::comma(summary_things$clean_site))
paste0(
"Total Sites Retained: ",
scales::comma(summary_things$clean_site)
)
}
})

# download dataset button - only appears if there data exists in the app already
output$dwn_working <- shiny::renderUI({
shiny::req(tadat$raw)
shiny::downloadButton(ns("download_working"),
"Download Working Dataset (.zip)",
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4",
contentType = "application/zip")
"Download Working Dataset (.zip)",
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4",
contentType = "application/zip"
)
})

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")
"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, "_working.zip")
Expand All @@ -193,19 +203,21 @@ mod_TADA_summary_server <- function(id, tadat) {
fs <- c()
tmpdir <- tempdir()
setwd(tempdir())
datafile_name = paste0(tadat$default_outfile, ".xlsx")
progress_file_name = paste0(tadat$default_outfile, "_prog.RData")
datafile_name <- paste0(tadat$default_outfile, ".xlsx")
progress_file_name <- paste0(tadat$default_outfile, "_prog.RData")
desc <- writeNarrativeDataFrame(tadat)
dfs <-
list(Data = TADA::TADA_OrderCols(tadat$raw), Parameterization = desc)
list(Data = EPATADA::TADA_OrderCols(tadat$raw), 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))
utils::zip(
zipfile = fname,
files = c(datafile_name, progress_file_name)
)
},
contentType = "application/zip"
)

output$download_final <- shiny::downloadHandler(
filename = function() {
paste0(tadat$default_outfile, "_final.zip")
Expand All @@ -214,21 +226,23 @@ mod_TADA_summary_server <- function(id, tadat) {
fs <- c()
tmpdir <- tempdir()
setwd(tempdir())
datafile_name = paste0(tadat$default_outfile, ".xlsx")
progress_file_name = paste0(tadat$default_outfile, "_prog.RData")
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)
list(Data = EPATADA::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))
utils::zip(
zipfile = fname,
files = c(datafile_name, progress_file_name)
)
},
contentType = "application/zip"
)

shiny::observeEvent(input$disclaimer, {
shiny::showModal(
shiny::modalDialog(
Expand All @@ -251,7 +265,7 @@ sort_removals <- function(removal_table) {
))
colnames(results) <- prefixes
results[is.na(results)] <- FALSE

for (prefix in prefixes) {
active_cols <- fields[dplyr::starts_with(prefix, vars = fields)]
if (length(active_cols) > 0) {
Expand All @@ -264,13 +278,13 @@ sort_removals <- function(removal_table) {
results["Flag and Filter"] <- (results$Flag & results$Filter)
results["Filter only"] <- ((totals == 1) & results$Filter)
results <-
dplyr::select(results,-intersect(prefixes, colnames(results)))
dplyr::select(results, -intersect(prefixes, colnames(results)))
results$Many <- rowSums(results) > 2
results$Retained <- !apply(results, 1, any)
counts <- colSums(results)
counts <-
data.frame(Reason = names(counts), Count = as.vector(counts))
counts <- counts[(counts$Count > 0),]
counts <- counts[(counts$Count > 0), ]
return(counts)
}
}
Expand Down
Loading

0 comments on commit 48b7259

Please sign in to comment.