 <p>You probably want to create two functions in R:</p> <ul> <li><code>getdata</code>: a function that retrieves the data from your database, and returns the data frame.</li> <li><code>makeplot</code> : a function with a dataframe argument that creates your plot and returns nothing.</li> </ul> <p>Then your client you can call them separately. First the client calls <code>getdata</code> to retrieve the data from the db, and the server will respond with a temporary <code>{key}</code> that represents the returned dataframe object on the server, for example <code>x01234567</code>.</p> <p>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:</p> <ul> <li><code>http://your.server.com/ocpu/tmp/x01234567/R/.val/csv</code></li> <li><code>http://your.server.com/ocpu/tmp/x01234567/R/.val/tab</code></li> <li><code>http://your.server.com/ocpu/tmp/x01234567/R/.val/json</code></li> </ul> <p>To create the plot, the client calls <code>makeplot</code> and passes <code>x01234567</code> as the argument value for the data frame. The <code>OpenCPU</code> server will automatically lookup the object for this key to the dataframe object that was returned before by <code>getdata</code>.</p>