I want to pass my R script from my node.js application to an Amazon EC2 instance running Ubuntu and Rserve; which would then execute and evaluate the R script and return the processed output back to my node.js application.
I found two reliable options:
1) RIO - (Used this)
2) rserve-client
Before proceeding to connect with Rserve, I made sure it was initiated and running.
ubuntu@ip-172-31-37-254:~$ sudo netstat -nltp|grep Rserve
tcp 0 0 0.0.0.0:6311 0.0.0.0:* LISTEN 5978/Rserve
Enabled the remote connection parameter for Rserve and got it started successfully.
library(Rserve)
Rserve(args="--RS-enable-remote")
Starting Rserve:
/usr/lib/R/bin/R CMD /usr/local/lib/R/site-library/Rserve/libs//Rserve --RS-enable-remote
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
During startup - Warning message:
Setting LC_CTYPE failed, using "C"
Rserv started in daemon mode.
1) Tried a test script using RIO package from my Node.js application
var rio = require("rio");
console.log("Connecting..");
rio.e({
host : "ec2-52-40-113-159.us-west-2.compute.amazonaws.com",
port : "6311",
command: "pi / 2 * 2",
callback: function (err, res) {
if (!err) {
console.log(res);
} else {
console.log("Rserve call failed. " + err);
}
}
// path :"/usr/local/lib/R/site-library"
});
Note: As stated here, I have the host parameter updated accordingly.
Error while running the app:
node app.js
Connecting..
Rserve call failed. Error: connect ETIMEDOUT 52.40.113.159:6311
I'm not sure, why is it that I am unable to connect. Is there any step that I am missing? Would also appreciate if there is any alternate package or way of accomplishing this task. Thanks.