Is breaking down my huge Shiny app into many smaller apps a good strategy to increase speed?

I have a very large Shiny app. Its functions are simple, but it is large because of the datasets and .RDS objects loaded. The app is categorized in as xxxlarge (the largest size). I will simplify the app for clarity of my question:

30 datasets and 30 .RDS objects (which are igraph objects used to plot networks) correspond to numbers 1-30. The app loads in ~15 seconds and user is presented with a dropdown menu, with options 1-30. If option 10 is selected, the app loads dataset#10 and .RDS file #10.

However, switching between datasets (especially if switching more than 2 or 3 times) brings things to a very slow speed, and occasionally even crashes or times out.

...So in principal would it be a good strategy for me to make 30 different Shiny apps? I have unlimited apps in my plan. I appreciate any comments, thanks!


It's hard to guess based on just the description why this app might be slow. There could be many reasons why and potentially many solutions.

In general, I don't think it's a good idea breaking an app up in multiple if one app can accomplish the same task, as each app will need to have its own resources and even if you have unlimited apps, that's not a real solution for the underlying problem.

Here are some general tips I can think of without knowing anything about your code:

  • Use databases: If you have a large amount of data that you don't all need in memory at the same time, create a database that can hold the data on disk and let R query only the data needed at runtime. SQLite is a very easy way to store data in a file format, and has fast reading speeds.
  • Remove unused data from memory: datasets that are not in use can be removed from memory and potentially speed up things
  • Load read-only data only once.: If you have a dataset that is large, but fits in memory and is read only, you can load it as a normal R variable outside the server function. This way, this dataset only gets read once and from then on resides in memory with much faster reading speeds
  • Beware of the server - client traffic: Apps often are slow because they have to send a lot of data back and forth between the client and server. For example, updating a ggplot with new data is an expensive task. On the other hand, using packages plotly or leaflet can prevent this going back and forth by sending data once to the client and having the filtering / interactivity performed there without the need for constant communication and updates

Feel free to share more info if you have a specific problem you're trying to tackle, but remember that sharing code can help a lot in order for us to understand.

Hope this helps,