I have spent considerable time troubleshooting this problem on SO but haven't been able to find a suitable answer. In short, I cannot view locally stored map tiles using R Shiny
and leaflet
.
I have used gdal2tiles.py to create a nested directory of tiles from an original high-resolution .tif file projected in EPSG:27700. The output of the tiling process can be viewed with the function's auto-generated .html files (i.e. googlemaps.html, leaflet.html, openlayers.html; see below for a link to a GitHub repo with the tiles and leaflet.html for viewing). I've therefore concluded that gdal2tiles.py is correctly generating the tiles which can be displayed in a browser.
The problem comes when attempting to use leaflet
and R Shiny
. I have followed the following instructions here and here to point leaflet
to my local tiles but nothing is displayed either within R Studio's viewer or my browser. It's frustrating because there are no errors printed to the R console when running the code. The code I am using, based on the previous SO answers I have just linked to looks like:
library(leaflet)
addResourcePath("mytiles", "C:/path/to/my/tiles/")
leaflet() %>%
addTiles(urlTemplate = "mytiles/{z}/{x}/{y}.png") %>%
addMouseCoordinates()
The folders and files are named correctly as per the syntax {z}/{x}/{y}
e.g. the directory structure looks like: path/to/my/files/6/30/42.png
. I have also uploaded my files to GitHub and passed the repo URL to urlTemplate
but to no avail. If it helps anyone, the tiles I am using can be found here. The repo is rather hefty in terms of the numbers of files and folders (the input raster is at 25m resolution and I require plenty of zoom levels), but not in size.
I have noticed--when zooming into my tiles in leaflet.html--that there are multiple shades of grey. This is weird because the input .tif was binary; either forest is present (1) or absent (NoData or NA). I have included a screenshot and wonder if this is a rendering problem within Chrome or whether this is causing the tiles to not show in Shiny
. The screenshot can be viewed here.
Could someone please help me display my tiles within R Shiny using local files? I will accept an answer if the best solution is to to GitHub-hosted tiles but my preference is to display locally-stored files.