Is it possible to trigger click event on leaflet drawToolbar?

For some reason I would like to draw polygon using button but not the one from the Toolbar, just my own button. In short, I want to click 'Click me!' button and start drawing polygon instead of choosing this option from toolbar. I tried to use jquery to trigger 'click' action on toolbar but can't do this at all. I noticed that 'buttons' on toolbar are not really buttons but simple classes. Maybe that's why I can't 'click' on them programatically. I also tried to use observeEvent but it doesn't work. Do you have any idea how can I trigger this action?

Here's working example:


ui <- fluidPage(
    actionButton("btn", label = "Click me!"),

server <- function(input, output, session) {
    coords <- quakes %>%
        sf::st_as_sf(coords = c("long","lat"), crs = 4326)

    output$map <- leaflet::renderLeaflet({
    leaflet::leaflet() %>% 
        leaflet::addTiles() %>% 
      leaflet::setView(172.972965,-35.377261, zoom = 4) %>%      
        data = coords,
        stroke = FALSE,
        radius = 6
        ) %>%         


shinyApp(ui, server)

and here's my jQuery code which should trigger 'draw polygon' option on toolbar but is not working:


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.