USEPA / TADAShiny

TADAShiny is a DRAFT R Shiny application (link to web version below) built on top of the TADA R Package (https://github.com/USEPA/TADA). It provides a user friendly, web accessible interface.
https://rconnect-public.epa.gov/TADAShiny/
Creative Commons Zero v1.0 Universal
11 stars 4 forks source link

Import tab missing country code filter #146

Closed cristinamullin closed 1 month ago

cristinamullin commented 7 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

image

JamesBisese commented 5 months ago

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 commented 5 months ago

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.