2

This is the source code of my Shiny app plotting polygons of more than 350 towns in Taiwan whenever there's any changed input from UI. Values of towns would change every time according to the inputs so there's little opportunity to do leafletProxy. Yet I am now having performance issues, especially on Shiny Server.

You may try running the app locally. The map would show up in like 10 seconds after the options are changed in UI. However, the deployed app on Google Compute Engine or on shinyapps.io takes so much longer (around 30 seconds) to depict the map, not only when initializing the app, but also every time the inputs are changed. Besides, the Shiny Server is frequently disconnected during computation like this:

App disconnected

When that disconnection happens, /var/log/shiny-server.log tells me:

[INFO] shiny-server - Error getting worker: Error: The application exited during initialization.

, which has never happened locally.

It doesn't make any sense to me. How is it possible that my laptop is beating servers? My laptop is MacBook Air (Early 2015) with just 1.6 GHz Intel Core i5 and 8 GB 1600 MHz DDR3, whereas the VM on Google Compute Engine performs so badly even when it has 4 vCPU and 15 GB RAM.

How can I possibly find out the reasons of worse performances on Shiny Server, or refactor my codes?


Can be related: Leaflet R performance issues with large map

ytu
  • 1,822
  • 3
  • 19
  • 42

1 Answers1

0

Well firstly - preprocessing has no place in the shiny application. Why repeat something every time someone uses the app when it can be done once and then that saved product can be loaded.

I'd have a look at the following steps:

  1. Remove anything that can be done once externally (e.g. Ln 12 - 37)
  2. Simplify the polygons to make the file smaller (faster loading, do this once and load in product)
  3. Anything you generate (labels etc) that are repetitively done, do once and save in a list (e.g. metadata.rds) and read in once and reference.

Sometimes it can appear that your app runs faster locally because you dont actually restart the session when developing - Shiny is basically kickstarting a session for each user (kinda).

zacdav
  • 4,603
  • 2
  • 16
  • 37
  • Thanks for the advices. Data preprocessing can indeed be removed and done externally. However, my performance problem is _not only at the app initialization but also every time the inputs are changed_, the app gives the map slower on servers than it does locally. – ytu May 13 '18 at 06:44
  • The polygons are meant to be that many so I don't know what you meant by "simplifying" them. Also everything I generate is changeable according to the inputs, so I don't see what is repetitively done. Would you please point out what exactly were you referring to? – ytu May 13 '18 at 06:47
  • Try `system.time` in the app. You'll find the execution time of `server` function is less than one second. You can also refer to [Leaflet R performance issues with large map](https://stackoverflow.com/questions/40063663/leaflet-r-performance-issues-with-large-map). – ytu May 14 '18 at 10:00
  • You've misunderstood - you can simplify the individual polygons such that the number of points to draw it is less and its essentially the same shape. If you can isolate the issues to be leaflet then that is its own problem. – zacdav May 15 '18 at 02:11