Search code examples
ropencpu

Are data objects persistent in openCPU's R session?


I would like to provide a web tool that requires access to a large dataset. Preferentially, this R data object should be loaded into memory once and then be available for user-defined queries.

Does the openCPU framework support persistant data objects in any way or does every query begin with a blank slate?


Solution

  • The OpenCPU API is stateless, there is no way to keep a process alive in between requests. But you can easily solve your problem by putting your dataset into a package, and installing that on the server.

    You can use the preload option described in the server manual, or use the /etc/opencpu/Rprofile script to load the package with the dataset in memory when the server starts. That way the data will be will be ready to use when requests come in.