When I go to my app on shinyapps.io it takes some time to load owing to a large amount of data that needs to be loaded. However if the app has been visited recently then it loads up instantly (presumably because the data is still loaded in from the previous instance.
Is there a way to keep my app permanently active in order to avoid the data loading stage, so that it loads up instantly each time it receives a a visit?
There's no way to keep data permanently loaded in an app. The only thing you can do is make the data file as small/fast as possible, e.g., save it as an rds or feather format. I like rds.
What I do is to put the data file in a dropbox folder (or similar). This makes it easy to update the data without redeploying the app.
I also do my data compressing (conversion to rds) in the app. When the app starts (actually I put it as a function call at the start of the server function), it checks the dropbox folder to see whether the compressed data file is already there; if so, it loads it. Otherwise it reads the big data file, and trims it down, then save the compressed file back to dropbox (with a .rds extention) for next time.
You can also improve the user experience by using showNotification() when the data is loading.
When I deploy my app to shinyapps.io it works just fine, provided I reduce the the "max worker process" to 1 (to keep the application's instance’s memory usage down). If it is much higher than 1, the app has a tendency to disconnect when there is more than one user. I believe this is due to the large data size.
(https://shiny.rstudio.com/articles/scaling-and-tuning.html)
This all works fine when the data loading takes places at the very start of the code. However when I move the data loading stage to the server (so that the user can see the front page while the data is loading), there is again a tendency for the app to disconnect when there are multiple users.
This suggests to me that, when the data is loaded upfront, multiple users are able to work off the same data. However when the loading takes place at the server stage, each user is using their own version of the data (thereby using up a lot of memory).
Is my assumption correct and do you know of any way to get around this issue?