Interactive Maps with tmap

library(sf)
library(tmap)

ws <- st_read("data/source/watersheds/WBDHU12.shp")

# Change tmap mode to "view" for interactive mapping
tmap_mode("view")

map <- tm_shape(ws, name = "watersheds") +
  tm_borders(col = "blue") +
  tm_basemap(c(OpenStreetMap = "OpenStreetMap", Imagery = "Esri.WorldImagery",
               Topo = providers$OpenTopoMap))
map

finalmap <- tm_shape(ws, name = "watersheds") +
  tm_polygons(col = "areaacres", n = 5, style = "pretty", alpha = 0.7,
              palette = hcl.colors(n = 5, palette = "YlGnBu"), title = "area(ac)") + 
  tm_scale_bar() +
  # Demonstrating two ways of specifying basemap providers.
  tm_basemap(c(OpenStreetMap = "OpenStreetMap", Imagery = "Esri.WorldImagery",
               Topo = providers$OpenTopoMap))
  
finalmap  
# Save the map as html
tmap_save(finalmap, "outputs/watersheds_interactiveMap.html")