[英]Creating a webservice running R scripts
Good morning everyone, 大家,早安,
I am starting to develop with R and I need to create a web service to execute some R scripts and have a JSON in return. 我开始使用R进行开发,并且需要创建一个Web服务来执行一些R脚本并返回JSON。
For example : 例如 :
When I go to this link http://myserver:1234/script/param1=xxx
当我转到此链接时
http://myserver:1234/script/param1=xxx
I want to execute an R script with the parameter xxx
and have in return a JSON for example with Hello World
我想执行带有参数
xxx
的R脚本,并以例如Hello World
的形式返回JSON
I found some tools as OpenCPU or DeployR but I couldn't manage to install them as DeployR needs an Windows Server and OpenCPU isn't well documented. 我找到了一些工具,例如OpenCPU或DeployR,但是由于DeployR需要Windows Server,并且没有详细记录OpenCPU,因此无法安装它们。
Any answer would be appreciated. 任何答案将不胜感激。
Please don't tell me it's duplicated because I couldn't find my answer there, DeployR isn't working for me. 请不要告诉我它是重复的,因为在那找不到我的答案, DeployR对我不起作用。
You could use our 5Analytics Platform. 您可以使用我们的5Analytics平台。 It allows you to deploy R or Python.
它允许您部署R或Python。 Just upload your code and it automatically generates webservices out of it.
只需上传您的代码,它就会自动从中生成Web服务。
Create a simple R script (can be complex too) 创建一个简单的R脚本(也可能很复杂)
# create simple R script
> echo "test_curl <- function() { 2 }" > test.R
Upload the script via webdav (or with a web gui) 通过webdav(或带有网络GUI)上传脚本
# upload file to server via webdav
> curl -u usr:pswd --digest -T test.R 'http://localhost:5050/up/dav/'
Query the webservice with http 使用http查询Web服务
> curl "http://localhost:5050/if/json/R/v1/test_curl?_token=test_token"
{
"data": [1.0]
}
Here some more documentation: http://doc.5analytics.com/ 这里有更多文档: http : //doc.5analytics.com/
Here a link to the homepage: https://www.5analytics.com/en/technology/ 这里是首页的链接: https : //www.5analytics.com/cn/technology/
An alternative might be using AWS Lambda. 一种替代方法是使用AWS Lambda。
In this excellent blogpost it is explained how to create an R microservice. 在这篇优秀的博客文章中,将介绍如何创建R微服务。
How does it work: 它是如何工作的:
You host an AWS Lambda function (=microservice) running Python that internally uses rpy2
to run your R-code. 您托管一个运行Python的AWS Lambda函数(= microservice),该函数在内部使用
rpy2
运行您的R代码。
Note that DeployR is obsolete. 请注意,DeployR已过时。 The replacement for it is R Server Operationalization , and it works with both Linux and Windows.
替代品是R Server Operationalization ,它可以在Linux和Windows上使用。
The operationalization feature for Microsoft R Server is supported on:
Microsoft R Server的操作功能受以下支持:
- Windows Server 2012 R2, Windows Server 2016
Windows Server 2012 R2,Windows Server 2016
- Ubuntu 14.04, Ubuntu 16.04,
Ubuntu 14.04,Ubuntu 16.04,
- CentOS/RHEL 7.x
CentOS / RHEL 7.x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.