I've made an interactive leaflet map using R Shiny. I was wondering if it was possible to hover over a polygon on the map and it displays certain information inside that polygon.
output$map = renderLeaflet({
setView(lng = -79.3832, lat = 43.6532 , zoom = 6, options = list(maxzoom = 5)) %>%
addPolygons(data = regiongeo, layerId = "region",fillOpacity = 0, weight = 2.5)})
labels<- paste("Region: " ,regionn$region_cd,"\n",
"Maximum CVA: ",regionn$max_cva, sep ="\n")
observeEvent(input$map_zoom,{
proxy<- leafletProxy("map")
if(input$map_zoom == 6)
{proxy %>% addPolygons(data = regiongeo , fillOpacity = 0,weight = 2.5,highlightOptions = highlightOptions(
color='#ff0000', opacity = 1, weight = 5.2, fillOpacity = 0,
bringToFront = TRUE, sendToBack = TRUE),label=labels,labelOptions= labelOptions(direction = 'auto'))}})
}
body<-navbarPage("MPAC Analytics", id="nav",
tabPanel("Interactive map",
div(class="outer",
tags$head(
includeCSS("styles.css"),
includeScript("gomap.js")
),
leafletOutput("map", height = "100%",width = "100%"),
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
width = 330, height = "auto",
h2("Analysis Box")))))
ui2 <-body
shinyApp(ui = ui2, server = server,onStart=global)