R (https://www.r-project.org/) is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS. In this example, I will be installing and configuring R on Ubuntu 14.04 and enabling R functionality with Tableau Server by installing the Rserve library.
In order to install R and R packages from the ‘Compreshensive R Archive Network’ (CRAN) we will use the Advanced Packaging Tool (APT) and therefre need add the repository to the list of sources as well as the public key to authenticate packages downloaded using APT, this will ensure we install the latest version of both R (r-base)and the CRAN package for Rserve.
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list' gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg -a --export E084DAB9 | sudo apt-key add - sudo apt-get update sudo apt-get install r-base
To verify the installation we can enter an interactive shell session, once loaded we shall quit the session
R q(save="no")
Now we will install the Rserve CRAN package by invoking the install.package() function in R. In order for the package to be available to all users this is installed as root (su).
sudo su - -c "R -e \"install.packages('Rserve', repos = 'http://cran.rstudio.com/')\""
Again, we can verify the installation by entering the R interactive shell session, confirming the Rserve library is available and then quit the session.
R library(Rserve) q(save="no")
By default Rserve only accepts local connections, in order to enable remote connections will we will need to modify the configuration file ‘/etc/Rserve.conf’. A detailed list of other Rserve connection properties that may be set see https://rforge.net/Rserve/doc.html#start.
remote enabled
In order to ensure the Rserve process is initialised at startyp as a daemon we will need to create the shell script ‘/etc/init.d/Rserve.sh’ as below. As no ownership of files are required for the invocation of the Rserve CRAN package, we will use the ‘nobody’ account to start the daemon.
#!/bin/bash sudo -u nobody R CMD Rserve --vanilla
In order to execute the shell script we will require to set execute permissions to the shell script and add a link to initialise the shell script at startup.
sudo chmod 755 /etc/init.d/Rserve.sh sudo update-rd.d /etc/init.d/Rserve.sh defaults
To confirm the Rserve process is initialised at startup using the shell script we can reboot the instance and confirm the process is running
ps aux | grep Rserve
The next step is optional, in this example I only want to permit inbound connections on the TCP service port 6311 (Rserve) from the Tableau Server. By default rules added to iptables are ephemeral and on restart will be removed. In order to save the configuration we will install the ‘iptables-persistent’ package.
sudo apt-get install iptables-persistent
I will firstly insert a drop rule for all connections (IPv4) to the destination port 6311(tcp), then insert an accept rule for the Tableau Server (10.0.0.2) to the destination port 6311(tcp) and then save the updates to preserve the iptables configuration.
sudo iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 6311 -j DROP sudo iptables -I INPUT -p tcp -s 10.0.0.2 --dport 6311 -j ACCEPT sudo service iptables-persistent save
The last step is to configure the Tableau Server VizSQL Server connection properties for a Rserve host (10.0.0.3) and port (6311) to enable R functionality within workbooks, optional configuration parameters are also available to use a username and password but in the example access is restricted by firewall rules.
tabadmin stop tabadmin set vizqlserver.rserve.host 10.0.0.3 tabadmin set vizqlserver.rserve.port 6311 tabadmin configure tabadmin start
The configuration is now complete, to verify the VizSQL Server configuration, invoke ‘tabadmin configure -o ‘ to confirm the configuration parameter has been set by dumping the current configuration to a file.