Leaflet map nested in RShiny App - Improving speed & portability

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Leaflet map nested in RShiny App - Improving speed & portability

Erin Stearns
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.

*Project description:*
I am creating a global map depicting binary malaria risk (at risk, not at
risk) at the Admin 2 level(current state only uses 5 countries and can be
found here <https://erstearns.shinyapps.io/malariarisk5/>).  I am using an
ESRI base map, then a polygons shapefile containing geometry and attributes
(geographical hierarchy & risk).

*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.

*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?

Thank you all, any insight is greatly appreciated.

Best,
Erin

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Tim Appelhans
Hi Erin,

a couple of thoughts regarding computation:

1. you could try using the preferCanvas option in leaflet(options =
leafletOptions(preferCanvas = TRUE) which likely won't help to speed up
the rendering but should make the map more responsive.

2. simplify your shapes using the rmapshaper package. Your shapes,
especially coastlines are quite detailed which puts heavy load on the
browser.

3. maybe use a simpler world file all-together with less details. I am
especially thinking of small islands and such.

(My personal priority list would be 3, 2, 1)

Regarding sharing I am not sure I understand. Do you mean sharing as in
hosting it somewhere on a server, or sharing a file (or similar) with
someone? If the latter, the RInno package may help (though only supports
windows).

HTH,

Tim


On 09/05/2018 01:56 AM, Erin Stearns 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.
>
> *Project description:*
> I am creating a global map depicting binary malaria risk (at risk, not at
> risk) at the Admin 2 level(current state only uses 5 countries and can be
> found here <https://erstearns.shinyapps.io/malariarisk5/>).  I am using an
> ESRI base map, then a polygons shapefile containing geometry and attributes
> (geographical hierarchy & risk).
>
> *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.
>
> *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?
>
> Thank you all, any insight is greatly appreciated.
>
> Best,
> Erin
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Roman Luštrik
In reply to this post by Erin Stearns
Regarding sharing, you will need to deploy this to a shiny server.
shinyapps.io offer a paid option which has more functionality and may work
for you if you don't have infrastructure capabilities. If you do, and I've
learnt of this just recently, another option is shinyproxy. It offer some
login capabilities, deploying through docker and is "easy" to setup
(provided nothing goes wrong).

Cheers,
Roman

On Wed, Sep 5, 2018 at 1:57 AM Erin Stearns <[hidden email]> 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.
>
> *Project description:*
> I am creating a global map depicting binary malaria risk (at risk, not at
> risk) at the Admin 2 level(current state only uses 5 countries and can be
> found here <https://erstearns.shinyapps.io/malariarisk5/>).  I am using an
> ESRI base map, then a polygons shapefile containing geometry and attributes
> (geographical hierarchy & risk).
>
> *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.
>
> *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?
>
> Thank you all, any insight is greatly appreciated.
>
> Best,
> Erin
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


--
In God we trust, all others bring data.

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Barry Rowlingson
In reply to this post by Erin Stearns
On Wed, Sep 5, 2018 at 12:56 AM, Erin Stearns <[hidden email]> 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
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Erin Stearns
Hello all,

Thank you all very much for the great insight!

*McCrea *- thank you very much, I will test using a geojson first, then
test after reducing geometry.

*Tim* - thank you for the great breakdown and recommended priority list.
Ideally, I would like to be able to share the interactive map with
teammates as a file or something akin to it such that they can simply open
it and interact with the map. RInno is a great option, however I run a
linux machine, so will look into further, but may need to find another
option.

*Roman* - the app is currently deployed to shinyapps.io. Thank you for
sharing about ShinyProxy -- so would this method require 1. Internet and 2.
local installation (vs internal server)?

*Barry* - wow, thank you for your response! Sounds like this would be the
best way to solve both issues. I am not as fluent with HTML and JS, but as
you say, there are likely great guides available to take this route.

Thank you all again, this has been hugely helpful. I wish you all the best
and hope I can be of help to you at some point!

Best,
Erin


On Wed, Sep 5, 2018 at 12:48 AM Barry Rowlingson <
[hidden email]> wrote:

>
>
> On Wed, Sep 5, 2018 at 12:56 AM, Erin Stearns <[hidden email]>
> 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
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Michael Treglia
I'll just second Barry's idea in particular, to set up as a standalone
webpage. You could even use QGIS and the QGIS2Web Plugin to create that,
and host via GitHub pages or similar.

From R, after creating a map via leaflet and similar packages, you can use
htmlwidgets::saveWidget() to export as a standalone .html file if I recall
correctly.

The one thing regarding a standalone webpage is that if you have a lot of
objects (especially complex ones), that can be a lot for a browser to
handle (given the data are part of the html file).  Might be worth some
quick experimentation, and simplifying polygons would help. (You could
always create a quick landing page, even generated via rMarkdown, and
having a link for maps by different regions or countries - then you could
have a folder of .html files you could distribute, and users could just
open the landing page, and navigate from there).

Just some quick thoughts... Hope this helps.
Mike T

On Wed, Sep 5, 2018 at 1:17 PM Erin Stearns <[hidden email]> wrote:

> Hello all,
>
> Thank you all very much for the great insight!
>
> *McCrea *- thank you very much, I will test using a geojson first, then
> test after reducing geometry.
>
> *Tim* - thank you for the great breakdown and recommended priority list.
> Ideally, I would like to be able to share the interactive map with
> teammates as a file or something akin to it such that they can simply open
> it and interact with the map. RInno is a great option, however I run a
> linux machine, so will look into further, but may need to find another
> option.
>
> *Roman* - the app is currently deployed to shinyapps.io. Thank you for
> sharing about ShinyProxy -- so would this method require 1. Internet and 2.
> local installation (vs internal server)?
>
> *Barry* - wow, thank you for your response! Sounds like this would be the
> best way to solve both issues. I am not as fluent with HTML and JS, but as
> you say, there are likely great guides available to take this route.
>
> Thank you all again, this has been hugely helpful. I wish you all the best
> and hope I can be of help to you at some point!
>
> Best,
> Erin
>
>
> On Wed, Sep 5, 2018 at 12:48 AM Barry Rowlingson <
> [hidden email]> wrote:
>
> >
> >
> > On Wed, Sep 5, 2018 at 12:56 AM, Erin Stearns <[hidden email]>
> > 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
> >> [hidden email]
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >>
> >
> >
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Erin Stearns
Thank you, Mike! Yes, I have used htmlwidgets, thank you for that! The
issue is the file begins unwieldy given the amount of data contained in my
leaflet app.

Yeah, it seems like there are a number of options, it's just trying to
determine the best is the tricky part.

Thanks again for the ideas - very much appreciated.

Best,
Erin



On Wed, Sep 5, 2018 at 11:02 AM Michael Treglia <[hidden email]> wrote:

> I'll just second Barry's idea in particular, to set up as a standalone
> webpage. You could even use QGIS and the QGIS2Web Plugin to create that,
> and host via GitHub pages or similar.
>
> From R, after creating a map via leaflet and similar packages, you can use
> htmlwidgets::saveWidget() to export as a standalone .html file if I recall
> correctly.
>
> The one thing regarding a standalone webpage is that if you have a lot of
> objects (especially complex ones), that can be a lot for a browser to
> handle (given the data are part of the html file).  Might be worth some
> quick experimentation, and simplifying polygons would help. (You could
> always create a quick landing page, even generated via rMarkdown, and
> having a link for maps by different regions or countries - then you could
> have a folder of .html files you could distribute, and users could just
> open the landing page, and navigate from there).
>
> Just some quick thoughts... Hope this helps.
> Mike T
>
> On Wed, Sep 5, 2018 at 1:17 PM Erin Stearns <[hidden email]> wrote:
>
>> Hello all,
>>
>> Thank you all very much for the great insight!
>>
>> *McCrea *- thank you very much, I will test using a geojson first, then
>> test after reducing geometry.
>>
>> *Tim* - thank you for the great breakdown and recommended priority list.
>> Ideally, I would like to be able to share the interactive map with
>> teammates as a file or something akin to it such that they can simply open
>> it and interact with the map. RInno is a great option, however I run a
>> linux machine, so will look into further, but may need to find another
>> option.
>>
>> *Roman* - the app is currently deployed to shinyapps.io. Thank you for
>> sharing about ShinyProxy -- so would this method require 1. Internet and
>> 2.
>> local installation (vs internal server)?
>>
>> *Barry* - wow, thank you for your response! Sounds like this would be the
>> best way to solve both issues. I am not as fluent with HTML and JS, but as
>> you say, there are likely great guides available to take this route.
>>
>> Thank you all again, this has been hugely helpful. I wish you all the best
>> and hope I can be of help to you at some point!
>>
>> Best,
>> Erin
>>
>>
>> On Wed, Sep 5, 2018 at 12:48 AM Barry Rowlingson <
>> [hidden email]> wrote:
>>
>> >
>> >
>> > On Wed, Sep 5, 2018 at 12:56 AM, Erin Stearns <[hidden email]>
>> > 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
>> >> [hidden email]
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >>
>> >
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

dirty-harry-ha
In reply to this post by Erin Stearns
Hey Erin,

I agree with everybody who answered, but just for completeness and FYI:

Another approach for sharing a Shiny app offline as a (Windows) Desktop
app might be using Shiny with "R portable".

For further details please check for example:
https://www.r-bloggers.com/deploying-desktop-apps-with-r/

Cheers!

Harry

Ps. If anybody thinks this is a very bad idea, please let me know,
because I'm planing to develop something like that ... Thanks!


Am 05.09.2018 um 01:56 schrieb Erin Stearns:

> 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.
>
> *Project description:*
> I am creating a global map depicting binary malaria risk (at risk, not at
> risk) at the Admin 2 level(current state only uses 5 countries and can be
> found here <https://erstearns.shinyapps.io/malariarisk5/>).  I am using an
> ESRI base map, then a polygons shapefile containing geometry and attributes
> (geographical hierarchy & risk).
>
> *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.
>
> *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?
>
> Thank you all, any insight is greatly appreciated.
>
> Best,
> Erin
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Michael Treglia
As a quick follow up, I just came across this blog post on serving up map
tiles via a GitHub repository, generating tiles via a QGIS plugin.
https://khufkens.com/2018/09/19/github-tile-server/

Not an R solution, but perhaps something that might help in a case like
this.  As explained, the solution would still require an internet
connection, but would otherwise be a lot l lighter than having a ton of
polygons in a single webpage.

Please pardon any typos, this message was sent from a mobile device.

On Wed, Sep 12, 2018, 2:27 PM <[hidden email]> wrote:

> Hey Erin,
>
> I agree with everybody who answered, but just for completeness and FYI:
>
> Another approach for sharing a Shiny app offline as a (Windows) Desktop
> app might be using Shiny with "R portable".
>
> For further details please check for example:
> https://www.r-bloggers.com/deploying-desktop-apps-with-r/
>
> Cheers!
>
> Harry
>
> Ps. If anybody thinks this is a very bad idea, please let me know,
> because I'm planing to develop something like that ... Thanks!
>
>
> Am 05.09.2018 um 01:56 schrieb Erin Stearns:
> > 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.
> >
> > *Project description:*
> > I am creating a global map depicting binary malaria risk (at risk, not at
> > risk) at the Admin 2 level(current state only uses 5 countries and can be
> > found here <https://erstearns.shinyapps.io/malariarisk5/>).  I am using
> an
> > ESRI base map, then a polygons shapefile containing geometry and
> attributes
> > (geographical hierarchy & risk).
> >
> > *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.
> >
> > *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?
> >
> > Thank you all, any insight is greatly appreciated.
> >
> > Best,
> > Erin
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > [hidden email]
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Leaflet map nested in RShiny App - Improving speed & portability

Michael Treglia
In reply to this post by Michael Treglia
Apologies- looks like that only supports raster tiles, as does the R
package 'tiler'.

Sorry for the multiple messages on this.
Cheers,
Mike

Please pardon any typos, this message was sent from a mobile device.

On Wed, Sep 5, 2018, 2:04 PM Michael Treglia <[hidden email]> wrote:

> I'll just second Barry's idea in particular, to set up as a standalone
> webpage. You could even use QGIS and the QGIS2Web Plugin to create that,
> and host via GitHub pages or similar.
>
> From R, after creating a map via leaflet and similar packages, you can use
> htmlwidgets::saveWidget() to export as a standalone .html file if I recall
> correctly.
>
> The one thing regarding a standalone webpage is that if you have a lot of
> objects (especially complex ones), that can be a lot for a browser to
> handle (given the data are part of the html file).  Might be worth some
> quick experimentation, and simplifying polygons would help. (You could
> always create a quick landing page, even generated via rMarkdown, and
> having a link for maps by different regions or countries - then you could
> have a folder of .html files you could distribute, and users could just
> open the landing page, and navigate from there).
>
> Just some quick thoughts... Hope this helps.
> Mike T
>
> On Wed, Sep 5, 2018 at 1:17 PM Erin Stearns <[hidden email]> wrote:
>
>> Hello all,
>>
>> Thank you all very much for the great insight!
>>
>> *McCrea *- thank you very much, I will test using a geojson first, then
>> test after reducing geometry.
>>
>> *Tim* - thank you for the great breakdown and recommended priority list.
>> Ideally, I would like to be able to share the interactive map with
>> teammates as a file or something akin to it such that they can simply open
>> it and interact with the map. RInno is a great option, however I run a
>> linux machine, so will look into further, but may need to find another
>> option.
>>
>> *Roman* - the app is currently deployed to shinyapps.io. Thank you for
>> sharing about ShinyProxy -- so would this method require 1. Internet and
>> 2.
>> local installation (vs internal server)?
>>
>> *Barry* - wow, thank you for your response! Sounds like this would be the
>> best way to solve both issues. I am not as fluent with HTML and JS, but as
>> you say, there are likely great guides available to take this route.
>>
>> Thank you all again, this has been hugely helpful. I wish you all the best
>> and hope I can be of help to you at some point!
>>
>> Best,
>> Erin
>>
>>
>> On Wed, Sep 5, 2018 at 12:48 AM Barry Rowlingson <
>> [hidden email]> wrote:
>>
>> >
>> >
>> > On Wed, Sep 5, 2018 at 12:56 AM, Erin Stearns <[hidden email]>
>> > 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
>> >> [hidden email]
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >>
>> >
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo