Learn R Programming

⚠️There's a newer version (2.2.2) of this package.Take me there.

An R Interface to Leaflet Maps

Leaflet is an open-source JavaScript library for interactive maps. This R package makes it easy to create Leaflet maps from R.

library(leaflet)
m = leaflet() %>% addTiles()
m  # a map with the default OSM tile layer

m = m %>% setView(-93.65, 42.0285, zoom = 17)
m

m %>% addPopups(-93.65, 42.0285, 'Here is the <b>Department of Statistics</b>, ISU')

Installation

You can install this package from CRAN, or the development version from GitHub:

# CRAN version
install.packages('leaflet')

# Or Github version
if (!require('devtools')) install.packages('devtools')
devtools::install_github('rstudio/leaflet')

Documentation

In addition to the usual R package documentation, we also have extensive docs and examples at: https://rstudio.github.io/leaflet/

Development

leaflet's JavaScript build tools use Node.js, along with yarn to manage the JavaScript packages.

Install yarn using the official instructions.

You can test that Node.js and yarn are installed properly by running the following commands:

node --version
yarn --version

To make additions or modifications to the JavaScript htmlwidgets binding layer, you must have all Node.js dependencies installed. Now you can build/minify/lint/test using yarn build, or run in "watch" mode by just running yarn watch. JS sources go into javascript/src and tests go into javascript/tests.

# install dependencies
yarn

# compile
yarn build

# watch
yarn watch

License

This package is licensed to you under the terms of the GNU General Public License version 3 or later.

Copyright 2013-2015 RStudio, Inc.

Copy Link

Version

Install

install.packages('leaflet')

Monthly Downloads

72,408

Version

2.1.1

License

GPL-3

Maintainer

Last Published

March 23rd, 2022

Functions in leaflet (2.1.1)

addLegend

Add a color legend to a map
aaa-test-viztest

Visual Testing scripts for vistest
addProviderTiles

Add a tile layer from a known map provider
addScaleBar

Add or remove a scale bar
iconList

Make icon set
getMapData

returns the map's data
groupOptions

Set options on layer groups
icons

Create a list of icon data
addRasterImage

Add a raster image as a layer
addAwesomeMarkers

Add Awesome Markers
addSimpleGraticule

setView

Methods to manipulate the map widget
breweries91

Selected breweries in Franconia
colorNumeric

Color mapping
providers

Providers
previewColors

Color previewing utility
leaflet

Create a Leaflet map widget
leaflet-imports

Objects imported from other packages
derivePolygons

Given a data object and lng/lat arguments (which may be NULL [meaning infer from data], formula [which should be evaluated with respect to the data], or vector data [which should be used as-is]) return a spatial object
tileOptions

Extra options for map elements and layers
createLeafletMap

Legacy functions
derivePoints

Given a data object and lng/lat arguments (which may be NULL [meaning infer from data], formula [which should be evaluated with respect to the data], or vector data [which should be used as-is]) return a lng/lat data frame.
expandLimits

Notifies the map of new latitude/longitude of items of interest on the map
dispatch

Extension points for plugins
leafletSizingPolicy

Leaflet sizing policy
makeAwesomeIcon

Make Awesome Icon
expandLimitsBbox

Same as expandLimits, but takes a polygon (that presumably has a bbox attr) rather than lat/lng.
removeControl

Remove elements from a map
addControl

Graphics elements and layers
makeIcon

Define icon sets
showGroup

Show or hide layer groups
safeLabel

Sanitize textual labels
addGraticule

addLayersControl

Add UI controls to switch layers on and off
validateCoords

Utility function to check if a coordinates is valid
easyButtonState

Create an easyButton statestate
evalFormula

Evaluate list members that are formulae, using the map data as the environment (if provided, otherwise the formula environment)
addMeasure

Add a measure control to the map.
awesomeIconList

Make awesome-icon set
filterNULL

remove NULL elements from a list
awesomeIcons

addMiniMap

leafletDependencies

Various leaflet dependency functions for use in downstream packages
gadmCHE

Administrative borders of Switzerland (level 1)
leafletProxy

Send commands to a Leaflet instance in a Shiny app
leafletOutput

Wrapper functions for using leaflet in shiny
mapOptions

Set options on a leaflet map object
addMapPane

Add additional panes to leaflet map to control layer order
atlStorms2005

Atlantic Ocean storms 2005
addTerminator

Add a daylight layer on top of the map