将 R 与 Apache & 结合使用PHP [英] Using R with Apache & PHP

查看:30
本文介绍了将 R 与 Apache & 结合使用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过 Apache 和 PHP 运行 R 脚本?我希望能够将变量从 PHP 传递到 R.

Is there anyway to run R scripts through Apache and PHP? I would like to be able to pass variables from PHP to R.

有人做过这样的事情吗?

Has anyone done something like this?

本质上,我想知道是否有一种方法可以将变量从 PHP 传递到 apache 服务器上的 R.

Essentially, I would like to know if there is a method for passing variables from PHP to R on an apache server.

推荐答案

我们个人使用 R CMD BATCH 接口到 R 来实现这一点.这不是很优雅,但本质上我们有一个用户将数据粘贴到一个表单中,该表单传递给 PhP,后者生成一个带有某些内容的 .R 文件

Personally we used the R CMD BATCH interface to R to achieve this. It's not very elegant, but essentially we have a user pasting data into a form which is passed to PhP which generates a .R file with something

x = c(1,2,3,4);dev.off();情节(x);

x = c(1,2,3,4); dev.off(); plot(x);

然后我们让 PhP 做一个 exec "R CMD BATCH "

Then we get PhP to do an exec "R CMD BATCH "

在该目录中,您应该获得可以提供给客户端的 Rplots.ps 文件.同样,您可以使用 jpeg() 函数返回图形的 jpeg 图片,然后可以在 PhP 返回的网页上显示.

In the directory you should then get Rplots.ps file which can be served to the client. Equally you can use the jpeg() function to return a jpeg picture of the graphic which can then be displayed on the web page PhP returns.

一点也不优雅,但对我们有用.

Not elegant at all, but it works for us.

这篇关于将 R 与 Apache & 结合使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆