shiny leaflet ploygon click event

Solution 1:

The click event in leaflet returns lat, lng and id (and a random value). So you can only access one of those elements.

The id value relates to the layerId you specify in the shape plotting function, so in your case that's layerId=~admin.

So you acccess the admin value through the click's id field

replace p$admin with p$id and you should have your solution.


If you want to see what's in the click event, just put a print statement around it

observeEvent(input$Map_shape_click, { # update the location selectInput on map clicks
  p <- input$Map_shape_click
  print(p)
})

and it will print the object to the console.