Introduction To Leaflet.

  • Leaflet is a broadly utilized open source JavaScript library used to assemble web mapping applications. First discharged in 2011, it bolsters generally portable and work area stages, supporting HTML5 and CSS3. Alongside OpenLayers, and the Google Maps API, it is one of the most famous JavaScript mapping libraries and is utilized by significant sites, for example, FourSquare, Pinterest and Flickr.
  • Leaflet permits engineers without a GIS foundation to effectively show tiled web maps facilitated on an open server, with discretionary tiled overlays. It can stack highlight information from GeoJSON records, style it and make intelligent layers, for example, markers with popups when clicked.
  • It is created by Vladimir Agafonkin, who joined Mapbox in 2013
  • Leaflet is planned with straight forwardness, execution and ease of use at the top of the priority list. It works effectively over all significant work area and portable stages out of the case, exploiting HTML5 and CSS3 on present day programs while being available on more established ones as well. It tends to be stretched out with a tremendous measure of modules, has a lovely, simple to utilize and well-archived API and a basic, lucid source code that is a delight to add to.
  • For more data, docs and instructional exercises, look at the official site.
  • For Leaflet downloads (counting the assembled ace variant), look at the download page.

Introduction to R Markdown

  1. The rmarkdown bundle (J. Allaire, Xie, McPherson, et al. 2019) was first made in mid 2014. During the previous four years, it has relentlessly developed into a moderately complete environment for composing reports, so it is a decent time for us to give a conclusive manual for this biological system now. Now, there are countless errands that you could do with R Markdown:
  2. Aggregate a solitary R Markdown record to a report in various organizations, for example, PDF, HTML, or Word.
  3. Make note pads in which you can straightforwardly run code lumps intuitively.
  4. Make slides for introductions (HTML5, LaTeX Beamer, or PowerPoint).
  5. Produce dashboards with adaptable, intuitive, and alluring formats.
  6. Assemble intuitive applications dependent on Shiny.
  7. Compose diary articles.
  8. Writer books of different parts.
  9. Produce sites and web journals.

We will be using a GUI Map and Plotting data For Indian Capital cities by using R markdown and Leaflet.js


  1. Open R Studio and click on New File.
  2. Click on R Markdown
  3. Install library
    1. Leaflet
    2. knitr
  4. Click the Link to Download the Data for Indian Capital cities.
    Data Tables
    1. State
    2. City
    3. Latitude
    4. Longitude
  5. Place Some Code
  6. Genrating Output and Publishig to R-Pubs

Step 1:

Open R Studio and click on New File and click on R MarkDown.

Step 2:

Input Your Desired Title Name of the Project and Author Name.

Step 3:

Install library
1. Leaflet
2. knitr
For Installing Library on Console write:

install.packages("leaflet") install.packages("knitr")

Then Call the Library
1. Leaflet
2. knitr

library(leaflet) library(knitr)

Reading the Csv file

You can click this link to Download the Data for Indian Capital cities.

Then Save the Lat and Long data to a variable for state_dim

state_capitals <- read.csv(&quot;indiacitieswithcapitals.csv&quot;) state_dim <- data.frame(Lat = state_capitals$Lat, Long = state_capitals$Long)

Step 4:

Implimenting the data and genrating the map.

Note : %>% <- derives to Pipe Operator.

Pipe (%>%) Operator

The principal function provided by the magrittr package is %>%, or what’s called the “pipe” operator. This operator will forward a value, or the result of an expression, into the next function call/expression. For instance a function to filter data can be written as:

filter(data, variable == numeric_value) or data %>% filter(variable == numeric_value)

Both functions complete the same task and the benefit of using %>% may not be immediately evident; however, when you desire to perform multiple functions its advantage becomes obvious.

state_dim %>% leaflet() %>% addTiles() %>% addMarkers(clusterOptions = markerClusterOptions())

You can also Add Awesome Markers in order to make your map more intractive and beautiful

addAwesomeMarkers(map, lng = NULL, lat = NULL, layerId = NULL, group = NULL, icon = NULL, popup = NULL, popupOptions = NULL, label = NULL, labelOptions = NULL, options = markerOptions(), clusterOptions = NULL, clusterId = NULL, data = getMapData(map))

Step 5:

Click on knitr and the click on knitr HTML to genrate output in html format.

Step 6:

Click on Publish to publish your map to R Pubs








Creating a web page using R Markdown that features a map created with Leaflet

Jatin chawda


library(leaflet) state_capitals <- read.csv("indiacitieswithcapitals.csv") state_dim <- data.frame(Lat = state_capitals$Lat, Long = state_capitals$Long) state_dim %>% leaflet() %>% addTiles() %>% addMarkers(clusterOptions = markerClusterOptions())





You can visit My R Pubs Published webpage: Click Here.

Leave a Reply