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

Import tab missing country code filter #146

Closed
cristinamullin opened this issue Mar 27, 2024 · 5 comments · Fixed by #165
Closed

Import tab missing country code filter #146

cristinamullin opened this issue Mar 27, 2024 · 5 comments · Fixed by #165
Assignees

Comments

@cristinamullin
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

There is ocean and data from other countries in the WQP that can be queried by a "country" code.

Country {"countrycode":["EM","OA","OI","OP","ZC"]}

Gulf of Mexico (STORET)
Atlantic Ocean (STORET)
Indian Ocean (STORET)
Pacific Ocean (STORET)
Caribbean Sea (STORET)

Describe the solution you'd like

Add country code filter on import tab. We could call it "country/ocean" to make it clear that users can search for oceans there as well. Generate list of countries and oceans from this domain:

FIPS code that identifies a country (e.g. countrycode = "CA" for Canada). See https://www.waterqualitydata.us/Codes/countrycode for options.

@JamesBisese
Copy link
Collaborator

On my computer, I have added this field to the UI and got it passed into the TADA query function. I need to learn which shiny ui element allows creating select list that has different strings for value and displayed in the list i.e. CA and Canada. The one used in other select list only accepts a value and displays it also i.e. CA and CA.

@JamesBisese
Copy link
Collaborator

JamesBisese commented May 23, 2024

To add the new filter I added code to mod_query_data.R

Get and prepare the filter options

# new (2024-05-23) list for new Country/Ocean(s) Query the Water Quality Portal option. Not included in saved query_choices file
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

Add the new UI element

    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))
    ),

Tweak the added new UI element

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

Add code to process argument for new UI element if selected

      if (is.null(input$countryocean)) {
        tadat$countryocean_value <- "null"
      } else {
        tadat$countryocean_value <- input$countryocean
      }

Finally, use it in the query that actually gets the data

      # storing the output of TADAdataRetrieval with the user's input choices as a reactive object named "raw" in the tadat list.
      raw <- TADA::TADA_DataRetrieval(
        statecode = tadat$statecode,
        countycode = tadat$countycode,
        countrycode = tadat$countryocean_value, # New filter added and simple testing. Use China 2018-05-01 2018-11-01
        huc = tadat$huc,
        siteid = tadat$siteid,
        siteType = tadat$siteType,
        characteristicName = tadat$characteristicName,
        characteristicType = tadat$characteristicType,
        sampleMedia = tadat$sampleMedia,
        project = tadat$project,
        organization = tadat$organization,
        startDate = tadat$startDate,
        endDate = tadat$endDate,
        applyautoclean = TRUE
      )

@JamesBisese
Copy link
Collaborator

image

@JamesBisese
Copy link
Collaborator

Use China with date range 2018-05-01 to 2018-11-01
Your dataset contains 70 unique results from 5 monitoring location(s) and 1 unique organization(s).

JamesBisese added a commit to JamesBisese/TADAShiny that referenced this issue Jun 5, 2024
Updates (should be) only to mod_query_data.R and are fixes for 3 issues - USEPA#140 Fix characterisitic group filter on impor tab, USEPA#146 Import tab missing country code filter, and USEPA#129 Add providers as a filter option on import tab.
@JamesBisese
Copy link
Collaborator

Testing

Use China with date range 2018-05-01 to 2018-11-01

Set Country/Ocean to 'China (People's Republic of)'
Your dataset contains 88 unique results from 63 monitoring location(s) and 1 unique organization(s).

Set Country/Ocean to 'Atlantic Ocean'
Your dataset contains 70 unique results from 5 monitoring location(s) and 1 unique organization(s).

Set Country/Ocean to 'China (People's Republic of)' and 'Atlantic Ocean'
Your dataset contains 158 unique results from 68 monitoring location(s) and 1 unique organization(s).

Do not set either (leave them blank)
... runs forever, but does not crash when no Country/Ocean filter is applied.
... eventually I closed the browser rather than wait for a huge dataset to be loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants