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]]

