问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/12468574/are-data-objects-persistent-in-opencpus-r-session