library(tidyverse)
library(sf)
library(maps)
ms_fips <- c("28009", "28033", "28093", "28137", "28143")
county.fips <- maps::county.fips
ms_map <- st_as_sf(maps::map("county", plot = FALSE, fill = TRUE)) %>%
inner_join(county.fips, by = c("ID" = "polyname")) %>%
filter(str_detect(ID, "^mississippi")) %>%
filter(!fips %in% ms_fips) %>%
ungroup() %>%
summarize(geom = sf::st_union(geom)) %>%
mutate(geo_name = "MS", fips = "28")
I am trying to make a map with specific counties compared to the rest of the state. Thus, I am using st_union() to aggregate the geometries for the rest of the counties. This process works fine locally, but fails when I try to deploy it to shinyapps (see error message below).
If I replace the st_union() call with st_combine(), it works both locally and online (but the inner borders for counties are retained, which is undesirable).
Error in value[[3L]](cond) : Problem with `summarise()` input `geom`.
✖ Evaluation error: TopologyException: Input geom 1 is invalid: Self-intersection at or near point -88.49768635253028 33.571661541724637 at -88.49768635253028 33.571661541724637.
ℹ Input `geom` is `sf::st_union(geom)`.