I have a shiny app that has a leaflet map in it with two different polygons. The leaflet map was working all good and fine until I updated my leaflet package to 2.0.1. Now when I run the app... the polygons aren't getting plotted and there are no errors being thrown at me. I have looked around and haven't found anything that fixes my problem. I would appreciate it if anyone can give me some guidance or point me in the right direction!
Working code before I updated leaflet:
library(shiny)
library(shinydashboard)
library(leaflet)
library(sf)
library(rmapshaper)
### Read in shapefiles ###
NJ_Map_Road<-st_read(getwd(),layer="2014_NJ_Integrated_Report_AU")
Impaired_HUCS<-st_read(getwd(),layer = "Impaired_HUCS_Shapefile")
### Change projection to work with leaflet ###
map_df <- st_transform(NJ_Map_Road, crs="+init=epsg:4326")
map_impaired_df<-st_transform(Impaired_HUCS,crs="+init=epsg:4326")
###########################################################################################
### simplify shapefiles ###
map_df<-ms_simplify(map_df)
map_impaired_df<-ms_simplify(map_impaired_df)
###########################################################################################
### This drop Z and M dimensions
good_map_df<- st_zm(map_df, drop = T, what = "ZM")
good_imp_map_df<- st_zm(map_impaired_df, drop = T, what = "ZM")
#################################################################
ui<- dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
box(width=12,leafletOutput("leaf"))))
### Server ###
server<- function(input,output,session){
### This creates interactive map ###
output$leaf<- renderLeaflet({
leaflet(options = leafletOptions(minZoom = 7))%>%
addTiles()%>%
addTiles(group = "OSM (default)") %>%
addProviderTiles(providers$OpenStreetMap.BlackAndWhite, group = "Grey") %>%
addProviderTiles(providers$Esri.WorldImagery, group = "Satellite") %>%
setView(lng = -74.4 ,lat =40, zoom = 7)%>%
addPolygons(data= good_map_df,color = "#636060",weight = 1,smoothFactor = 1,
opacity = 0.5, fillOpacity = 0.1,group = "HUCs",fillColor = "white",
highlightOptions = highlightOptions(color = "blue",
weight = 2,bringToFront = TRUE))%>%
addPolygons(data = good_imp_map_df,color = "#F3161B",weight = 1,smoothFactor = 1,
opacity = 0.5, fillOpacity = 2,
group = "Impaired HUCs",
highlightOptions = highlightOptions(color = "blue",
weight = 2,bringToFront = TRUE),
label = ~ paste(HUC14TXT,AU_name),
layerId = ~ good_imp_map_df$AU_name)%>%
addLayersControl(
baseGroups = c("OSM (default)", "Grey", "Satellite"),
overlayGroups = c("HUCs","Impaired HUCs"),
options = layersControlOptions(collapsed = FALSE))%>%
addLegend("bottomright",colors = c("#636060","#F3161B"),opacity = 2,
labels = c("HUC14s","Impaired HUCs"))
})
###########################################################################################
### Allows user to have map zoomed in when impaired HUC is clicked ###
observe({
click <- input$leaf_shape_click
if(is.null(click))
return()
else
leafletProxy("leaf")%>%
setView(lng = click$lng , lat = click$lat, zoom=10)
})
}
shinyApp(ui,server)