Polygon drawing in Leaflet not triggering draw:created event in Shiny app

Hello Shiny Community,

I am working on a Shiny app that includes a Leaflet map with drawing capabilities. Users should be able to draw polygons on the map, and when the drawing is complete, the app is supposed to capture the draw:created event and perform some server-side actions.

However, I am encountering an issue where drawing a polygon does not trigger any response in my Shiny server function. Below is the simplified version of my server code for handling the event:

###############################################
library(shiny)
library(leaflet)
library(leaflet.extras)

ui <- fluidPage(
leafletOutput("map")
)

server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(lng = 2.3522, lat = 48.8566, zoom = 12) %>%
addDrawToolbar()
})

observeEvent(input$map_draw_created, {
cat("Draw event triggered\n")
})
}

shinyApp(ui = ui, server = server)
##############################################

I expect the console to print "Draw event triggered" after completing the drawing of a polygon, but nothing is appearing in the console. There are no errors in the R console or the browser's JavaScript console. I have verified that the drawing tools appear on the map and I can draw polygons, but the event does not seem to be captured by observeEvent.

I'm using the latest versions of Shiny, Leaflet, and the leaflet.extras packages.

Could you please help me understand what might be going wrong? Any guidance or suggestions would be greatly appreciated.

Thank you in advance for your assistance!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.