You probably want to create two functions in R:
getdata
: a function that retrieves the data from your database, and returns the data frame.makeplot
: a function with a dataframe argument that creates your plot and returns nothing.
Then your client you can call them separately. First the client calls getdata
to retrieve the data from the db, and the server will respond with a temporary {key}
that represents the returned dataframe object on the server, for example x01234567
.
Then you can use this key to either download the dataset or use it as an argument to create the plot. To download the data, simply create a hyperlink to for example:
http://your.server.com/ocpu/tmp/x01234567/R/.val/csv
http://your.server.com/ocpu/tmp/x01234567/R/.val/tab
http://your.server.com/ocpu/tmp/x01234567/R/.val/json
To create the plot, the client calls makeplot
and passes x01234567
as the argument value for the data frame. The OpenCPU
server will automatically lookup the object for this key to the dataframe object that was returned before by getdata
.