addSpinner: Add Spin Plugin

View source: R/spin.R

addSpinnerR Documentation

Add Spin Plugin

Description

Adds an animated loading spinning over the map.

Usage

addSpinner(map)

startSpinner(map, options = NULL)

stopSpinner(map)

Arguments

map

A map widget object created from leaflet

options

Spin.js options. Named list. See http://spin.js.org

Value

A leaflet map object

Shiny

startSpinner() and stopSpinner() in the same leaflet or leafletProxy chain are sent to the browser together. Use spinWhile (or start the spinner, then run the work after session$onFlushed).

References

https://github.com/makinacorpus/Leaflet.Spin

https://github.com/fgnass/spin.js

See Also

Other Spinner Functions: spinWhile()

Examples

library(leaflet)

leaflet(data = quakes) %>%
  addTiles() %>%
  addSpinner() %>%
  startSpinner(options = list("lines" = 7, "length" = 20)) %>%
  addMarkers(~long, ~lat, popup = ~ as.character(mag), label = ~ as.character(mag)) %>%
  stopSpinner()

## Not run: 
library(shiny)
shinyApp(
  ui = fluidPage(
    actionButton("go", "Load markers"),
    leafletOutput("leaf")
  ),
  server = function(input, output, session) {
    output$leaf <- renderLeaflet({
      leaflet() %>%
        addTiles() %>%
        addSpinner()
    })
    observeEvent(input$go, {
      spinWhile("leaf",
        {
          Sys.sleep(2)
          leafletProxy("leaf") %>%
            addMarkers(data = quakes, ~long, ~lat)
        },
        options = list(lines = 7, length = 20)
      )
    })
  }
)

## End(Not run)

leaflet.extras2 documentation built on Sept. 10, 2026, 1:11 a.m.