[prev in list] [next in list] [prev in thread] [next in thread]
List: r-sig-mac
Subject: Re: [R-SIG-Mac] R with PHP on mac
From: Simon Urbanek <simon.urbanek () r-project ! org>
Date: 2005-12-01 16:43:48
Message-ID: 0FA5BC60-E963-4D99-933C-DA7C67FA4FEE () r-project ! org
[Download RAW message or body]
Yannick,
On Nov 27, 2005, at 12:15 PM, Yannick Huot wrote:
> My understanding is that the bitmap function will not work on OS X,
> because it has to be used with X11 or the GUI interface of R.
That is true, although you can run a virtual X11 server (Xvfb
supplied with Apple's X11).
> We thus installed the GDD library and changed the R code to the
> following keeping the PHP code the same:
There is one important difference - GDD currently does not send the
image to stdout - it is always written into a file which is by
default "plot.png". You may try something like this which I tested
successfully on OS X but should also work on any unix:
<?
$tmpf = tempnam("/tmp", "plot"); $fn="$tmpf.png";
$cmd = "echo 'fn<-\"$fn\"; source(\"/tmp/t.r\")' | " .
"/usr/bin/R --vanilla --slave";
$out = shell_exec($cmd);
if (file_exists($fn) && filesize($fn)>0) {
$p = file_get_contents($fn);
header("Content-type:image/png");
echo $p;
} else {
header("Content-type:text/plain");
echo "Something went wrong (fn=$fn):\n\n";
echo $out;
}
if (file_exists($fn)) unlink($fn);
if (file_exists($tmpf)) unlink($tmpf);
?>
it also includes some error handling code, so it may ease debugging.
The corresponding R code:
library(GDD)
GDD(fn,type="png8")
plot(1:10)
invisible(dev.off())
Cheers,
Simon
[[alternative HTML version deleted]]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic