Integrating R code with a web server

1.2k views Asked by At

Overview: Need to integrate R library with a web server written in python. I have explored some of the options commonly mentioned on different blogs and stack overflow threads. The threads I have come across compare libraries like Rpy2 and pypeR and provide specific answers to integrate R and python. What I am looking for is a general solution so that the R code can be accessed by a multitude of programming languages/clients (for future extensibility).

Requirements:

  1. R code should run separately to handle heavy computation and not be embedded into the application server.
  2. R module should be scalable and easily maintainable. ex- any change to the application server (written in python) should not trigger changes in the R code.
  3. R module can be used as an API for further application development using web frameworks other than python.

Options already explored:

  1. rpy2, pypeR: One option is to write a separate python server and let that server handle R code using rpy2. The app server can send requests to the second server.
  2. Rserve and pyRserve: Use Rserve and pyRserve client to communicate between R and python.
  3. Apache Thrift and Protocol Buffer: rprotobuf is an interface for R to make it work with Protocol Buffer but I could not find any support for R in Apache Thrift. Will something like Thrift or protocol buffer be better than creating an R server.
  4. Rapache and Rook: Use Rapache and Rook package in R to setup a server for processing requests.
  5. deployR: Created by Revolution Analytics.

Which among these would be an ideal choice or any other option which is not in the list?

2

There are 2 answers

1
JensG On

Regarding Apache Thrift bindings:

  • First, Apache Thrift does not have native bindings for R1).

  • Second, from what I read so far (I am not an R user), there are plenty of options to integrate R into other host languages. Thrift offers support for C++, C, Java, Python and a plethora of other targets and languages, 20+ in total. So it seems possible to create a host application offering the Thrift API and housing the R stuff.


1) Today. I can't look into the future, and things change quickly sometimes.

0
lgautier On

Did you consider the following ?

  • Python has a package to interface with Thrift / create thrift servers.
  • Rpy2 is an interface to R (and arguably the fastest one).

web server <---> Thrift server (Python) (Python + rpy2)