C. Lewis
15-November-2015
Objective: Using the Yelp Dataset Challenge, construct a Shiny application that allows users to search for restaurants with specific amenities and a range of review ratings (stars). Display the resulting search on a map the can be zoomed and panned.
The first step is to read and process the JSON data.
The second step is to create a subset of data that will be used for the shiny application:
Finally, the pre-processed data is saved off to a file for use in the Shiny application to facilitate fast rendering of the map.
Leaflet is JavaScript library that works as an add-on to R and allows for the development of interactive maps.
library(leaflet,quietly=TRUE)
library(maps,quietly=TRUE)
# Read pre-processed data
bizrates<-read.table("bizrates.dat")
# Build out a leaflet object
mymap<-leaflet() %>%
addTiles() %>%
addTiles(urlTemplate = "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png") %>%
mapOptions(zoomToLimits="always") %>%
addMarkers(lat=bizrates$biz_rest.latitude,lng=bizrates$biz_rest.longitude,
clusterOptions = markerClusterOptions(),popup=bizrates$biz_rest.business_id)
# And display it
mymap
Unfortunately it does not render in RPresentation slides (see the HTML in github to see it in action; image is on next page). The report developed in association with his presentation has a live working version of the map.
More on leaflet can be found here: https://rstudio.github.io/leaflet/
User can select: