Calling R as a web service with parameters and load a JSON?
If you have not done so yet please checkout [DeployR]. You can also post questions to the DeployR Google Group for help.
For full disclose I am one of the authors of DeployR
Overview
DeployR is an integration technology for deploying R analytics inside web, desktop,mobile,and dashboard applications as well as backend systems. DeployR turns your R scripts into analytics web services, so R code can be easily executed by applications running on a secure server.
Using analytics web services, DeployR also solves key integration problems faced by those adopting R-based analytics alongside existing IT infrastructure. These services make it easy for application developers to collaborate with data scientists to integrate R analytics into their applications without any R programming knowledge.
DeployR is available in two editions: DeployR Open and DeployR Enterprise. DeployR Open is a free, open source solution that is ideal for prototyping, building, and deploying non-critical business applications. DeployR Enterprise scales for business-critical applications and offers support for production-grade workloads, as well as seamless integration with popular enterprise security solutions such as single sign-on (SSO), Lightweight Directory Access Protocol (LDAP), Active Directory, or Pluggable Authentication Modules (PAM).
I am pretty new with R
Prefect. DeployR is intended for both the Data Scientist as well as the application developer who might not know R.
What I am trying to do is to be able to load a URL from another application (Java) which will run an R script and output a JSON so my application can work with it.
DeployR does this quit well. To aid in the communication between your application and the DeployR server (that will be executing your R) there are the DeployR Client libraries.
Depending on your needs, DeployR has out-of-the-box 'client library' support in:
- Java-client-library:
https://github.com/deployr/java-client-library
- .NET-client-library:
https://github.com/deployr/dotnet-client-library
- JavaScript and Node.js-library:
https://github.com/deployr/js-client-library
DeployR also supports the RBroker Framework
should your use-case or runtime anticipate a high-volume workload or the need for periodic, scheduled or batch processing.
I understand there are some frameworks like shiny which act as web servers for R, but I can't find documentation on those frameworks on how to pass parameters via the URL so R can use them
DeployR acts as your analytics engine through its APIS. Basically think of it as turning your R scripts into secure analytic web services to be consumed like any other web service.
Pass parameters
Passing parameters to an R Script in DeployR is easy, however you have to understand that you are passing parameters to an R Script from a language that is not R. As such, there is some 'Data Encoding' that needs to be done. For example, turn your Java String into an R character
or your Java boolean to an R logical
...
The DeployR Client library or RBroker makes this easy.
It sounds like you are using Java, so first review the Java tutorial java-example-client-basics https://github.com/deployr/java-example-rbroker-basics
to give you some context then checkout the many Java examples under java-example-client-data-io https://github.com/deployr/java-example-client-data-io
.
The example source is fully available so that should give you everything you need
in order to understand how to do basic I/O from your application to the DeployR server for your R analytics.
Ideally I will need to call a URL like:
http://127.0.0.1/R/param1/param2
I suggest using the DeployR Client libraries for your communication as described above, it does just that.
As always post questions to the DeployR Google Group https://groups.google.com/forum/#!forum/deployr
for help.
You have some options to do that, IMHO OpenCPU is a nice one.
It's the simplest open source way to implement a web server to provide R computation as a REST service.
The creator of OpenCPU is the same author of jsonlite package, and you can easily get and pass json parameters with OpenCPU, as you can see here.