I'm using R to create plots and I want to retrieve the resulting PNG or PDF file in node. The idea here is to provide an HTTP API that can launch an R script and return an image computed by R.
Here is a rough example:
var R = require('rstats');
var util = require('util');
var h = new R.session();
h.parseEvalQ('require("ggplot2");');
h.parseEvalQ('p <- qplot(carat, price, data = diamonds);');
Now, I'd like to export a PNG file and send it to node. But ggsave doesn't seem to be able to write the content of the file to a variable. I tried using var content = h.get('p') but it failed:
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Error evaluating: toJSON(p);
Of course I could use ggsave to save to a temporary file which node could read, but I'm looking for a way to do this without even touching the hard drive… I'm not really R-savvy; does anyone have any idea on how to achieve this?
Closing this as using a temporary file is in fact what RInside's creator did with his Wt application (see source here); this will do just fine for us at the moment.
I'm using R to create plots and I want to retrieve the resulting PNG or PDF file in node. The idea here is to provide an HTTP API that can launch an R script and return an image computed by R.
Here is a rough example:
Now, I'd like to export a PNG file and send it to node. But
ggsave
doesn't seem to be able to write the content of the file to a variable. I tried usingvar content = h.get('p')
but it failed:Of course I could use
ggsave
to save to a temporary file which node could read, but I'm looking for a way to do this without even touching the hard drive… I'm not really R-savvy; does anyone have any idea on how to achieve this?