我试图使用运行从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