RStudio has released a package to bind Leaflet to Shiny page, built on their htmlwidgets . Using this package, it is trivial to write a shiny app that contains a leaflet map. To begin, we need to install the leaflet package from github:
Shown above is a basic shiny program to display a slippy map using open street map tiles, the live example can be explored here. So how hard is it to get those GIBS layers in there? Looking at the NASA Earthdata map viewer we can note some issues:
- most layers have a date component to the URI
- not all layers have the same available date range
- not all layers are available in all projections
- some layers are intended to be overlays
Sticking with web mercator (EPSG:3857), the first task is to sort out all the available layers. Here is some code to read the XML capabilities file and parse out the useful bits:
It appears that the file type (png or jpeg) is the key to determining if the layer is a base layer or an overlay. The other bits that need to be pulled out are the maximum zoom factor and available date ranges. Using these fields, we can specify the layer(s) we want to show with the following shiny code segments:
Some hard-coding done here to select the coastlines overlay, and the calendar range was set by inspection of the current dataset. Here is a live version of the application.
The source code for this application is available at gihub: