Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure FastRWeb to use RServer built-in web server

Tags:

r

rserve

I'm new to RServe (and FastRWeb). I installed RServe 1.7.0 as I want to use its built-in webserver. As I already have apache running on this machine I want to run RServe/FastRWeb on a custom port.

I did cd /usr/local/lib/R/site-library/FastRWeb;sudo ./install.sh, which created /var/FastRWeb/ directory tree.

I'm not seeing any configuration file that mentions port. The default /var/FastRWeb/code/rserve.conf looks like this:

socket /var/FastRWeb/socket
sockmod 0666
source /var/FastRWeb/code/rserve.R
control enable

I'm guessing that means it uses unix sockets, by default? So I think my question is what exactly do I have to put in (and remove from) that file to, say, have it listen on TCP port 8888? And is there anything else I need to do? (I want to be able to connect from other machines, not just localhost.)

Possibly related, is I've looked at /var/FastRWeb/web/index.html and it contains javascript that is going to connect to /cgi-bin/R/ Is that path specific to when using Apache, or is it going to be fine, as-is, when using RServe?

like image 734
Darren Cook Avatar asked Feb 16 '23 15:02

Darren Cook


2 Answers

There is an explanation of setting port in the Rserve 1.7.0 release announcement. Therefore, at the top of rserve.conf, I added this line: http.port 8888 Then I used the start script (as root), to start it.

This got me halfway as now http://127.0.0.1:8888/ works, but gives me a page that says:

Error in try(.http.request("/", NULL, NULL, c(48, 6f, 73, 74, 3a, 20,  : 
  could not find function ".http.request"

The second half of the solution is to add this to the top of /var/FastRWeb/code/rserve.R:

library(FastRWeb)
.http.request <- FastRWeb:::.http.request

Then start things going by running /var/FastRWeb/code/start. There is no default handler, so you can test it with http://127.0.0.1:8888/info. Or a more interesting example is http://127.0.0.1:8888/example1.png (to view a chart) or http://127.0.0.1:8888/example2 (to view a mix of html and chart)

Note: I did not delete or edit any other configuration to get this working. That means we also have the unix socket listening. If that is not needed remove those two lines from the Rserve.conf file.

If you want it listening on all IP addresses, not just localhost, then add remote enable to your Rserve.conf file. NOTE: Make sure you understand the security consequences before opening your server to the world.

So, after those two changes, my /var/FastRWeb/code/Rserve.conf file looks like:

http.port 8888
remote enable
source /var/FastRWeb/code/rserve.R
control enable
like image 147
Darren Cook Avatar answered Feb 19 '23 23:02

Darren Cook


Did you see Jay Emerson's write-up from a while back about how to use RServe as a backend for web-driven analysis? As I recall, one still uses Apache for the redirection, rather than an explicit port as you surmise here.

Jay's setup was very impressive. He used Rserve to provide mixed table/chart pages written via the grid package, all very slick and very fast, based of an immense data set (from a UN agency, or the World Bank, or something). But I can't find a link to that report right now...

like image 30
Dirk Eddelbuettel Avatar answered Feb 19 '23 23:02

Dirk Eddelbuettel