top of page

My first interactive map using Shiny and Leaflet -1


Hi there

In this post, I'm gonna talk about my first experience of working with interactive maps.

But let me start off with something I have recently noticed about my posts. I have felt that they are becoming more like update posts instead of scientific posts. So I promise to get back on track and be more technical in my posts, and I guess there won't be any rush for finishing up a topic anymore.

As I said in this post I'm gonna talk about the interactive maps and how to create them in R and Shiny.

You know ? my first reaction when I found out this map has been made by R was like: WTF, noooo waaaay. Because I had not seen or done such cool thing before with R.

I'm gonna introduce you to how to make static maps and then we can get into the interactive maps. There are actually different packages for creating a map using R out there such as rMaps, maps or leaflet., but I'm gonna intoroduce the later one in this post.

Leaflet used to be just a Javascript library and being used by web developers, but ever since the R programmers became able to create html widgets and make bridge between R and html, almost everthing has became possible for R programmers to integrate these two. It's kinda trivial but Leaflet uses an object oriented approach and they have objectified every single thing in a map. So you would be able to add/remove every single feature you need for your map just by adding or removing its object. Take a look at a simple example :

m <- leaflet() %>% addTiles() %>% addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")

print(m)

What happens is ......, the leaflet() function just create a map object and put it in 'm', while the addTiles() adds the basemap and the addMarkers puts a marker on a specific coordinate.

Isn't that cool and easy ?

But I guess the coolest feature of Leaflet is the fact that it lets to add your layer (shape file or what ever it is) to your base map and do some analysis. There are a tons of 'add...' functions provided by leaflet that you can add polygon, line, circle or what ever you want.

Let me tell you something that, if you want to really get into it, you need first enough about the sptial analysis and how to use some packages like 'sp', 'rgdal' and/or 'rgeos'.

I promise you guys, it just needs lots of practices.

Featured Posts
Recent Posts
Archive
Search By Tags
bottom of page