Below are the solutions to these exercises on Leaflet Package – Part 2.”
# load package library(leaflet) #################### # # # Exercise 1 # # # #################### leaflet() %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) )#################### # # # Exercise 2 # # # #################### leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines()
#################### # # # Exercise 3 # # # #################### colors_palette <- colorNumeric( palette = rev(x = heat.colors(nrow(atlStorms2005))), domain = range(atlStorms2005$MaxWind) ) leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines( color = ~colors_palette(MaxWind), opacity = 0.65 )
#################### # # # Exercise 4 # # # #################### leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines( color = ~colors_palette(MaxWind), opacity = 0.65 ) %>% addLegend(pal = colors_palette, values = ~MaxWind)
#################### # # # Exercise 5 # # # #################### leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines( color = ~colors_palette(MaxWind), opacity = 0.65, highlightOptions = highlightOptions(weight = 10) ) %>% addLegend(pal = colors_palette, values = ~MaxWind)
#################### # # # Exercise 6 # # # #################### leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines( color = ~colors_palette(MaxWind), opacity = 0.65, highlightOptions = highlightOptions(weight = 10), label = ~Name ) %>% addLegend(pal = colors_palette, values = ~MaxWind)
#################### # # # Exercise 7 # # # #################### leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines( color = ~colors_palette(MaxWind), opacity = 0.65, highlightOptions = highlightOptions(weight = 10), label = ~Name, popup = ~paste("Min Press.", MinPress) ) %>% addLegend(pal = colors_palette, values = ~MaxWind)
#################### # # # Exercise 8 # # # #################### my_leaflet <- leaflet(data = atlStorms2005) %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon("home"), title= "Reset Zoom", onClick = JS( c("function(btn, map) {map.setView(new L.LatLng(39.75, -47.4), 3);}") ) ) ) %>% addPolylines( color = ~colors_palette(MaxWind), opacity = 0.65, highlightOptions = highlightOptions(weight = 10), label = ~Name, popup = ~paste("Min Press.", MinPress) ) %>% addLegend(pal = colors_palette, values = ~MaxWind) htmlwidgets::saveWidget(widget = my_leaflet, file = "my_leaflet.html")
Leave a Reply