如何在网页上设置基于 R 的服务 [英] How to set up an R based service on a web page
问题描述
我想在网页上提供以下服务:
I would like to provide the following service on a webpage:
- 每天运行一个 R 脚本来收集公开可用的数据并进行一些计算(我已经开发了该脚本,它需要一些额外的库!)
- 在网页上发布更新的图形和数字/文本输出
我不想一直运行自己的电脑,所以应该采用一种云解决方案(我猜?!?).
I don't want to run my own computer all the time so a kind of a cloud solution should be employed (I guess?!?).
您对如何实现上述想法有什么想法吗?
Do you have any ideas how to accomplish the above ideas?
推荐答案
您可以查看 FastRWeb - 它为 R 脚本提供服务如果它们是网页并且支持图形以及常规输出.它使用 Rserve,这使它比任何涉及启动 R 的解决方案(例如 R
或 Rscript
)快得多.它可以通过 CGI 或 PHP 在任何网络服务器上运行.
You may have a look at FastRWeb - it serves R scripts as if they were web pages and supports graphics as well as regular output. It uses Rserve which makes it much faster than any solution that involves starting R (such as R
or Rscript
). It works on any webserver wither via CGI or PHP.
生成绘图的脚本如下所示:
A script to generate a plot would look like:
run <- function(n=100, ...) {
p <- WebPlot(800, 600)
n <- as.integer(n)
plot(rnorm(n), rnorm(n), col=2, pch=19)
p
}
其他解决方案是 RApache,它将 R 直接嵌入到 apache 网络服务器中.
Other solution is RApache which embeds R directly into the apache webserver.
还有 Jeff 现在Rook使用嵌入式 R HTTP 服务器(感谢 Joshua 指出这一点).
And also by Jeff there is now Rook that uses the embedded R HTTP server (thanks to Joshua for pointing that one out).
您提到每天运行 - 如果您不需要在线分析,您可以简单地使用 R 生成 html
页面和 png
文件并将它们发送到您的网络服务器 -全部在一个自动化脚本中.有很多 R 包可以促进 HTML 输出 - 只需在 CRAN 包列表中搜索 HTML.
You mentioned running it daily - if you don't need online analysis, you can simply generate html
pages and png
files with R and send them to your webserver - all in an automated script. There are many R package that facilitate HTML output - just search in the CRAN package list for HTML.
这篇关于如何在网页上设置基于 R 的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!