Show leaflet spinner when rendering slow leaflet map in shiny

I added the following code to your app.R. You can see that the loading message works when loading the map, but when adding the markers it does not work. This is my problem. By the way I am using a custom spinner for the loading. Please don't spent too much time on this, I do not consider it vital to my project.

# in ui
 actionButton("plotbutton", label = "Add Markers"),

# in server
  observeEvent(input$plotbutton, {
    show_loading(elem = "leafletBusy")
    dlat <- 1/111000*100 # degrees per metre
    leafletProxy("map") %>% 
      addMarkers(lng = -93.65+(runif(5000)*2-1)*dlat*3, 
                 lat = 42.0285+(runif(5000)*2-1)*dlat)
    hide_loading(elem = "leafletBusy")
  })
1 Like