简体   繁体   中英

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.

For example :

When I go to this link 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

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.

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.

You could use our 5Analytics Platform. It allows you to deploy R or Python. Just upload your code and it automatically generates webservices out of it.

Create a simple R script (can be complex too)



    # create simple R script
    > echo "test_curl <- function() { 2 }" > test.R

Upload the script via webdav (or with a web 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



    > curl "http://localhost:5050/if/json/R/v1/test_curl?_token=test_token"
    {
        "data": [1.0]
    }

Here some more documentation: http://doc.5analytics.com/

Here a link to the homepage: https://www.5analytics.com/en/technology/

An alternative might be using AWS Lambda.

In this excellent blogpost it is explained how to create an R microservice.

How does it work:

You host an AWS Lambda function (=microservice) running Python that internally uses rpy2 to run your R-code.

Note that DeployR is obsolete. The replacement for it is R Server Operationalization , and it works with both Linux and Windows.

The operationalization feature for Microsoft R Server is supported on:

  • Windows Server 2012 R2, Windows Server 2016
  • Ubuntu 14.04, Ubuntu 16.04,
  • CentOS/RHEL 7.x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM