Hello,
I hope this is the right place to post this question, if not, please
redirect me.
I am trying to help someone trying to use R with PHP on the mac. I'm
no PHP, UNIX, or R expert, but the local mac helper (so very
unqualified for this...), you will have to bear with me here!
We have started with an example found here : http://
www.math.ncu.edu.tw/~chenwc/new/myjob/R_note/index.php?
item=php&subitem=ex_2
It is said to be only for "Linux" only, but we tried ou luck with it
on OS X.
The PHP code:
<?
$cmd = "echo 'argv <- \"ex_2.r\"; source(argv)' | " .
"/usr/bin/R --vanilla --slave";
$handle = popen($cmd, "r");
$ret = "";
do{
$data = fread($handle, 8192);
if(strlen($data) == 0){
break;
}
$ret .= $data;
}
while(true);
pclose($handle);
header("Content-type:image/png");
echo $ret;
?>
The R code:
dev.off.wrap <- function(){
dev.off()
invisible()
}
bitmap(file = "%stdout", type="png256")
pie(rep(1, 24), col = rainbow(24))
dev.off.wrap()
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. We thus
installed the GDD library and changed the R code to the following
keeping the PHP code the same:
autoload("GDD","GDD")
dev.off.wrap <- function(){
dev.off()
invisible()
}
GDD(type="png")
pie(rep(1, 24), col = rainbow(24))
dev.off.wrap()
I have verified this code directly in the terminal and it works fine!
Others things I know:
-R and PHP are communicating fine with each other, I can get a print
() command in R to display in the browser
-The problem seems occurs at the GDD command line (I can get the print
() command to work before this line but not after), but I have no
idea, why!
Any help you can offer with this problem will be much appreciated.
Cheers
Yannick
Laboratoire d'Océanographie de Villefranche
B.P. 8
06238 Villefranche-sur-Mer Cedex
France
Téléphone : +33 (0)4 93 76 39 11
Fax: +33 (0)4 93 76 37 39
[[alternative HTML version deleted]]
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac