R/mod_side_geography_utils_selection.R

Defines functions get_geo_choices

get_geo_choices <- function(
  dataset,
  sel_country = NULL,
  sel_subnational = NULL,
  sel_local = NULL,
  sel_maa = NULL,
  target = NULL
) {
  out <- dataset
  if (!is.null(sel_country)) {
    out <- out %>% dplyr::filter(country == sel_country)
  }
  if (!is.null(sel_subnational)) {
    out <- out %>% dplyr::filter(level1_name %in% sel_subnational)
  }
  if (!is.null(sel_local)) {
    out <- out %>% dplyr::filter(level2_name %in% sel_local)
  }
  if (!is.null(sel_maa)) {
    out <- out %>% dplyr::filter(ma_name %in% sel_maa)
  }
  
  out %>% 
    dplyr::pull(target) %>% 
    unique() %>% 
    sort()
}
Rare-Technology/ECO_Dashboard documentation built on May 6, 2023, 3 p.m.