One of the much anticipated features of Tableau 8.1 is integration with R. Following is a compilation of notes and observations about this integration for those of you beginning to use this new feature. This was done using 8.1 Desktop and R installed on the same Windows machine.

Installation

I used 32-bit R 3.0.2. 32-bit was chosen to ensure compatabilitiy with Rserve. To install Rserve, open R and do the following from the command line: install.packages(“Rserve”) library(Rserve) Rserve() When Rserve needs to be restarted, simply do b and c above.

Note: If you plan to use Tableau Server with R in a production environment, it is strongly recommended that Rserve not be run on a Windows platform.

Connecting Tableau to R

This is quite easy to do, but a strong word of caution:

Select Help-> Settings and Performance-> Manage R Connection from the menu. Enter the appropriate Server and Port information. Credentials also go here. If you are connecting to Rserve running on your own Windows machine, you will likely want to use 127.0.0.1 for your Server and 6311 for your Port.

Note: It may be tempting to use localhost as your Server instead of 127.0.0.1, but I recommend that you refrain. It will work, but there is noticeable performance degradation if you do this.

Using R

R is used within Tableau by creating a calculated field. Four functions exist, differing only in what data type it expects to receive back from R. These functions are SCRIPT_BOOL, SCRIPT_INT, SCRIPT_REAL, and SCRIPT_STR. The expression that R will evaluate should be in quotes, and the parameters you wish Tableau to send to R should be designated as arg1, arg2, etc. in that expression. After the expression, those parameters need to be defined.

I decided to do a simple linear regression in R and compare the results to the Tableau trendline. The function lm in R performs this regression, but it sends back multiple values. Since Tableau expects a single result back from R, I also made use of the coefficients function and created two calculated fields in Tableau (one for slope and one for intercept).

A sample calculation for slope is shown below. Arg1 is the y-axis.

The following dashboard shows a scatter plot with Tableau generated trend lines. The text display makes use of the R calculated fields. Below the dashboard is the Tableau trend line description for the Student A trend line, demonstrating that the slope and intercept values from Tableau match those generated by R.