Using R with Tableau 8.1: Getting Started

Data

Using R with Tableau 8.1: Getting Started

by Todd Robeson

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

  1. I used 32-bit R 3.0.2. 32-bit was chosen to ensure compatabilitiy with Rserve.
  2. To install Rserve, open R and do the following from the command line:
    1. install.packages(“Rserve”)
    2. library(Rserve)
    3. Rserve()
    4. 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: 

  1. Select Help-> Settings and Performance-> Manage R Connection from the menu.
  2. 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.

Sample Calculation for Slope

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. 

Aggregated Analysis

Describe Trend Line

More About the Author

Todd Robeson

Data Engineer
Using R with Tableau 8.1: Getting Started One of the much anticipated features of Tableau 8.1 is integration with R. Following is a compilation of notes and observations about ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072