[R-sig-Geo] Leaflet map nested in RShiny App - Improving speed & portability

Barry Rowlingson b@rowling@on @ending from l@nc@@ter@@c@uk
Wed Sep 5 09:48:25 CEST 2018


On Wed, Sep 5, 2018 at 12:56 AM, Erin Stearns <estearns88 using gmail.com> wrote:

> Hello all!
>
> I hope this message finds you all well!
>
> I have 2 questions pertaining to the creation of interactive maps via
> Leaflet nested inside an RShiny app. One question has to do with
> computation while the other has to do with sharing/off-line interactivity.
>
> *Computation question*
> As you see, the RShiny app takes quite a bit of time to render. Does anyone
> have any suggestions for improving this? As previously said, this version
> only contains 5 countries, thus I cannot continue with my current method to
> reach a global map. I have considered finding centroids of all Admin 2
> polygons and retaining attribute information here, then rasterizing the
> malaria risk shapefile for visualization and using the 2 instead of a
> single shapefile with polygon boundaries and attributes.
>
>
Unless you plan to add any computational functions to this map then I'd
strongly recommend creating it as a standalone web app and not a shiny app.
This will enable you to use lots of useful Leaflet plugins for speeding
things up, such as only showing country outlines at low zoom levels, and
showing subdivisions only at high zoom levels. This *might* be possible
with R's various leaflet packages but I'd go for full javascript control.

A standalone map would take its data from a JSON file or similar, and you
would then be writing R code that generated that. The mapping app itself is
written in HTML and JS with CSS styling. There are plenty of guides to
web-based interactive mapping, starting with Leaflet.


> *Sharing the app/offline interactivity*
> I am planning to share this with people who likely do not have R installed
> on their laptops nor have they ever coded. Does anyone have any suggestions
> for the best way to do this while retaining interactivity?
>
>  Here's the big win of creating a standalone web map. You only have to
distribute the HTML/CSS/JS and they can be viewed directly (or you also
supply a tiny server that runs locally and only has to feed the files on a
localhost port). No need to have a shiny server anywhere, or install R. Its
simple and clean. It also needs no network connectivity, but you'll not get
a base map - but you could include a low or medium resolution basemap
raster in your package.

The only reason to need Shiny here would be if you wanted people to do
something computational, like click on a bunch of polygons and then fit a
linear model to the selection, since that would require a round-trip to the
server for R to compute the fit. (although I suspect there's a JS package
for linear modelling.... you can do ML in JS these days...)



> Thank you all, any insight is greatly appreciated.
>
> Best,
> Erin
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list