如何解决php中exec()实现R代码的Rscript路径问题
我正在尝试在 PHP 中运行 R 代码, 这是我的代码:
index.php
<html>
<head>
<title>PHP and R Integration Sample</title>
</head>
<body>
<div id="r-output" style="width: 100%; padding: 25px;">
<?php
// Execute the R script within PHP code
// Generates output as test.png image.
exec("Rscript sample.R");
?>
<img src="test.png?var1.1" alt="R Graph" />
</div>
</body>
</html>
sample.R
x <- rnorm(6,1)
png(filename="test.png",width=500,height=500)
hist(x,col="red")
dev.off()
之后我发现我收到了这样的 Apache 错误:
'Rscript' is not recognized as an internal or external command,operable program or batch file.
我尝试按照此链接中的评论Conecting R with php, 然后我更新了我的代码:
index.php
<html>
<head>
<title>PHP and R Integration Sample</title>
</head>
<body>
<div id="r-output" style="width: 100%; padding: 25px;">
<?php
// Execute the R script within PHP code
// Generates output as test.png image.
exec("C:\Program Files\R\R-4.0.3\bin\Rscript sample.R");
?>
<img src="test.png?var1.1" alt="R Graph" />
</div>
</body>
</html>
在那次更新之后,我在 apache 中收到了这条消息:
'C:\Program' is not recognized as an internal or external command,operable program or batch file.
如果我在解释之前提到的链接上的评论时出错,请告诉我。 请帮助我在 PHP 中实现 R 代码,为我提供最佳用例建议。感谢任何答案。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。