我試圖使用運行從PHP的R腳本如下:R和PHP集成
echo "<form action='poorman.php' method='get'>";
echo "Number values to generate: <input type='text' name='N' />";
echo "<input type='submit' />";
echo "</form>";
if(isset($_GET['N']))
{
$N = $_GET['N'];
// execute R script from shell
// this will save a plot at temp.png to the filesystem
exec("Rscript my_rscript.r $N");
// return image tag
$nocache = rand();
echo("<img src='temp.png?$nocache' />");
}
和我的[R腳本如下所示:
args <- commandArgs(TRUE)
N <- args[1]
x <- rnorm(N,0,1)
png(filename="temp.png", width=500, height=500)
hist(x, col="lightblue")
dev.off()
它不產生臨時。 png
r腳本很好,但似乎我無法從php執行此腳本。任何幫助將不勝感激?
注意使用ubuntu。 謝謝,
我假設你已經測試過直接運行R腳本並驗證它確實在那種情況下產生了所需的png? – joran
是的,它工作正常 – jkjk
可能的重複:http://stackoverflow.com/questions/4818641/using-r-through-php – aL3xa