Search code examples
rshinyr-leaflet

Saving and reloading leaflet renders


I know this strays from the preferred "here is my code, here is the specific bug" format of Stack Overflow, but I am trying to be as specific as I can with the knowledge that I have at the moment.

I have some rather larger (~500mb) geoTIFF files that I would like to display on a shiny dashboard. I would like to preserve as much of the original information as possible, without making it agonizingly and prohibitively slow. I was wondering if there was a way to save the rendered map and reload it, instead of having the map be regenerated each time the script was run--this data is static enough that there is no point in re-rendering it multiple times.

Here is a brief demo:

library(leafem)
library(leaflet)

leaflet() %>%
   addTiles()%>%
      leafem::addGeotiff(
         file="map.tif",
      )

Ultimately, the leafem::addGeotiff() term could just as easily be addRasterImage() if it is possible to save the render, but I have found it to be faster at the moment.

Thanks for any and all help!


Solution

  • If anyone ever sees this question in the future, I wanted to link the solution I ended up going with: How to render custom map tiles created with gdal2tiles in Leaflet for R?. The solution is ultimately to use the gdal2tiles.py script to convert the .tif image to png tiles that can be loaded onto the map in the same way as the basemap.