library(leaflet)
library(tidyverse)
load("data/muni_recode.rda")
county_geom <- sf::st_read("inst/app/www/county.shp", quiet = TRUE)
ctv_geom <- sf::st_read("inst/app/www/ctv.shp", quiet = TRUE)
# Read and clean it
# ctv_geom <- sf::st_read("C:/W_shortcut/files/map/CTV_Jan_2020.shp", quiet = TRUE)
# ctv_geom <- ctv_geom |> dplyr::mutate(county_code = stringr::str_sub(DOR, end = 2), county_code = as.integer(county_code), county_code = ifelse(CNTY_NAME == "Menominee", 73, county_code)
# )
# ctv_geom |> dplyr::count(county_code,CNTY_NAME) |> as.data.frame()
# ctv_geom <-
# sf::st_as_sf(x = ctv_geom,
# # coords = c("lng", "lat"),ctv_geom
# crs = 4326,
# na.fail = FALSE)
# ctv_geom = sf::st_transform(ctv_geom, "+proj=longlat +datum=WGS84")
# ctv_geom |> dplyr::select(1:8, county_code) |> sf::st_write("inst/app/www/ctv.shp")
ctv_geom_filter = ctv_geom |> dplyr::filter(CNTY_NA == "Brown")
bell = crash |> dplyr::filter(MUNICODE %in% c( "503"))
crash_lat_long_j <-
bell %>% dplyr::select(lng, lat, CRSHSVR) %>% # [, .(lng, lat, CRSHSVR)] %>%
dplyr::filter(!is.na(lng), !is.na(lat))# remove crashes with no lat/long
crash_lat_long_j = rbind(crash_lat_long_j, crash_lat_long_j)
# convert to sf so we can map it!
crash_lat_long_j <- sf::st_as_sf(
x = crash_lat_long_j,
coords = c("lng", "lat"),
crs = 4326
)
crash_lat_long_j = sf::st_transform(crash_lat_long_j, "+proj=longlat +datum=WGS84")
ctv_geom_filter <- ctv_geom |> filter(CNTY_NAME == "Brown")
# sf::st_write()
leaflet() |>
# leafgl::addGlPoints(
# data = crash_lat_long_j,
# radius = 5,
# ) |>
addProviderTiles(providers$CartoDB.Voyager, options = providerTileOptions(opacity = .5)) %>%
# addTiles(options = providerTileOptions(opacity = .5)) %>%
addPolygons(
data = county_geom$geometry,
group = "Counties",
color = "#444444",
fillOpacity = 0,
weight = 1,
smoothFactor = 0.5
# options = pathOptions(clickable = FALSE)
) |>
addPolygons(
data = ctv_geom_filter$geometry,
group = "CTV",
color = "#444444",
fillOpacity = 0,
weight = .5,
smoothFactor = 0.5,
options = pathOptions(clickable = FALSE)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.