Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filters Country and Provider to Load tab to #164

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ _snaps

# Trip's testing file
flagged.csv
.idea
renv.lock
inst/golem-config.yml

.RDataTmp
renv/activate.R
app.R
saved.Rhistory
77 changes: 64 additions & 13 deletions R/mod_query_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

load("inst/extdata/statecodes_df.Rdata")
load("inst/extdata/query_choices.Rdata")

# new (2024-05-23) list for new Country/Ocean(s) Query the Water Quality Portal option. Not included in saved query_choices file
library(jsonlite)
library(dplyr)
url <- 'https://www.waterqualitydata.us/Codes/countrycode?mimeType=json'
countryocean_source <- fromJSON(txt=url)
countryocean_source <- countryocean_source$codes %>% select(-one_of('providers'))
countryocean_source <- countryocean_source[order(countryocean_source$desc),]
countryocean_choices <- countryocean_source$value
names(countryocean_choices) <- countryocean_source$desc

# Last run by EDH on 08/25/23
# county = readr::read_tsv(url("https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt"), col_names = FALSE)
# county = county%>%tidyr::separate(X1,into = c("STUSAB","STATE","COUNTY","COUNTY_NAME","COUNTY_ID"), sep=",")
Expand Down Expand Up @@ -90,16 +101,19 @@ mod_query_data_ui <- function(id) {
shiny::textInput(ns("huc"), "Hydrologic Unit", placeholder = "e.g. 020700100103")
)
),
shiny::fluidRow(column(
4,
shiny::selectizeInput(
ns("siteid"),
"Monitoring Location ID(s)",
choices = NULL,
multiple = TRUE
)
)),
htmltools::h4("Metadata Filters"),
shiny::fluidRow(
column(4,
shiny::selectizeInput(ns("siteid"),
"Monitoring Location ID(s)",
choices = NULL,
multiple = TRUE)),
column(4,
shiny::selectizeInput(ns("countryocean"),
"Country/Ocean(s)",
choices = NULL,
multiple = TRUE))
),
htmltools::h4("Metadata Filters"),
shiny::fluidRow(
column(
4,
Expand Down Expand Up @@ -149,7 +163,12 @@ mod_query_data_ui <- function(id) {
),
column(
4,
shiny::selectizeInput(ns("chargroup"), "Characteristic Group", choices = NULL)
shiny::selectizeInput(
ns("chargroup"),
"Characteristic Group",
choices = NULL,
multiple = TRUE
)
),
column(
4,
Expand All @@ -161,6 +180,14 @@ mod_query_data_ui <- function(id) {
)
)
),
shiny::fluidRow(
column(
4,
shiny::checkboxGroupInput(ns("providers"),
"Data Source",
Copy link
Collaborator

@hillarymarler hillarymarler Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesBisese - is it possible for the provider filter default setting to be both providers checked? To mimic WQP querying interface. If the user unchecks both boxes, it would be ideal to still query both providers but provide a message that both users are being queried because the user has not made any provider selection(s).

c("NWIS (USGS)" = "NWIS", "WQX (EPA)" = "STORET"))
)
),
shiny::fluidRow(column(
4,
shiny::actionButton(ns("querynow"), "Run Query", shiny::icon("cloud"),
Expand Down Expand Up @@ -317,6 +344,17 @@ mod_query_data_server <- function(id, tadat) {
server = TRUE
)


shiny::updateSelectizeInput(
session,
"countryocean",
choices = countryocean_choices,
selected = character(0),
options = list(placeholder = "Start typing or use drop down menu"),
server = TRUE
)


# this observes when the user inputs a state into the drop down and subsets the choices for counties to only those counties within that state.
shiny::observeEvent(input$state, {
state_counties <- subset(county, county$STUSAB == input$state)
Expand Down Expand Up @@ -352,6 +390,17 @@ mod_query_data_server <- function(id, tadat) {
} else {
tadat$countycode <- input$county
}
# this is an overloaded field which can be 2-character Country or Ocean
if (is.null(input$countryocean)) {
tadat$countrycode <- "null"
} else {
tadat$countrycode <- input$countryocean
}
if (is.null(input$providers)) {
tadat$providers <- "null"
} else {
tadat$providers <- input$providers
}
if (input$huc == "") {
tadat$huc <- "null"
} else {
Expand All @@ -362,7 +411,7 @@ mod_query_data_server <- function(id, tadat) {
} else {
tadat$siteType <- input$type
}
if (input$chargroup == "") {
if (is.null(input$chargroup)) {
tadat$characteristicType <- "null"
} else {
tadat$characteristicType <- input$chargroup
Expand All @@ -380,7 +429,7 @@ mod_query_data_server <- function(id, tadat) {
if (is.null(input$project)) {
tadat$project <- "null"
} else {
tadat$project <- input$project
tadat$project <- paste(input$project, collapse = ",")
}
if (is.null(input$org)) {
tadat$organization <- "null"
Expand Down Expand Up @@ -417,6 +466,7 @@ mod_query_data_server <- function(id, tadat) {
raw <- EPATADA::TADA_DataRetrieval(
statecode = tadat$statecode,
countycode = tadat$countycode,
countrycode = tadat$countrycode,
huc = tadat$huc,
siteid = tadat$siteid,
siteType = tadat$siteType,
Expand All @@ -427,6 +477,7 @@ mod_query_data_server <- function(id, tadat) {
organization = tadat$organization,
startDate = tadat$startDate,
endDate = tadat$endDate,
providers = tadat$providers,
applyautoclean = TRUE
)

Expand Down
24 changes: 21 additions & 3 deletions app.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# Launch the ShinyApp (Do not remove this comment)
# To deploy, run: rsconnect::deployApp()
# Or use the blue button on top of this file
library(devtools)

pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE)
options( "golem.app.prod" = TRUE)
TADAShiny::run_app() # add parameters here (if any)
# pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE)

options( "golem.app.prod" = FALSE)

# detach all attached packages and clean your environment
golem::detach_all_attached()

golem::set_golem_options()

# document and reload your package
golem::document_and_reload()

options(shiny.launch.browser = .rs.invokeShinyWindowExternal)

# TADAShiny::run_app() # add parameters here (if any)
run_app()
run
# pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE)
# options( "golem.app.prod" = TRUE)
# TADAShiny::run_app() # add parameters here (if any)
2 changes: 1 addition & 1 deletion inst/golem-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ default:
production:
app_prod: yes
dev:
golem_wd: !expr here::here()
golem_wd: !expr golem::pkg_path()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JamesBisese - I can fix/restore the unintentional changes to app.R and golem-config.yml. Once you get a chance to update the provider filter settings, I will merge this pull request. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the GUI element I have on my computer. It uses the metaphor of having 3 radio buttons - USGS, WQX, and Both.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original check boxes work fine. In a new PR (#165), I made it so both are checked by default:

image

Loading