Keeping a shiny app active on shinyapps.io

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.

Here's an example
https://github.com/woodwards/breeding_worth/blob/master/breeding_worth0.54.R

Here's the app
https://dairynz.shinyapps.io/breeding_worth/

Thanks Simon, that's really useful.

The link to your R file no longer seems to work. If you are able to send me the new link that would great.

Thank again

You might need to be logged in to Github. If you are already logged in try going to here first

https://github.com/woodwards/breeding_worth/

Thanks Simon,

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?

Thank very much for your help

So you will need to load the data in the global part of the app, and try to make the data as small and fast loading as possible.