Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R : Load only once a .RData in a deployed ShinyApp

I need to deploy a ShinyApp with Shiny Server. To run, my app need data from a .RData file (~300 Mo). This .RData file is loaded with a load(...) statement located in a global.R file. Function of the computer, the loading may need several minutes what is unfriendly for the user.

How can we do in order to make the .RDate file load only once so that each new user does not need to re-load the .RData file ?

Thanks.

like image 747
JPL Avatar asked Oct 30 '22 23:10

JPL


1 Answers

If you load the object in global.R, then just once it should be loaded. Every user after the first should have a fast access to your application.

If you are developing locally your app, you can test what I'm saying in the following way. Start your application with, for instance,

 runApp(port=5050)

just to set the port. You need some time for your browser to display the app. After loading, take note of the address of your app (should be 127.0.0.1:5050), close the browser tab of the app (but don't stop R!), open a new tab and put the above address in the address bar. Now, access to your app should be very fast.

This just to say that as long as shiny is up and running, the commands in global.R are executed at the beginning and their evaluation is put in the R global environment. They are not executed any time a user connects to the app.

Consider also that you can speed up the loading of an Rdata if you save it with the compress=FALSE argument. In this way, your file will be bigger, but loading it will be faster.

like image 161
nicola Avatar answered Nov 15 '22 05:11

nicola