We are now part of Eviden, discover more...

In the world of Self-Service BI, Tableau is one of the leading solutions. Its visualizations and ad-hoc analysis capabilities have given it an edge over other Self-Service BI tools. One of Tableau’s most striking features is the ability to build custom ‘Calculated fields’ inside the report with the help of its library of built-in functions.  

Today, it has become essential for BI solutions to provide a means to connect with tools such as R and Python to enable on-the-fly Data Science analyses such as Predictive modeling, Sentiment Analysis, Text Mining, etc. On this front too, Tableau delivers successfully with its R and Python integration. 

The Tableau- R integration is a huge relief for Data Scientists and Analysts who are currently grappling with the problem of creating intuitive and interactable visualizations with their models created in R and presenting it to their users. Forget the hassle of working in different environments for predictive modeling and reporting. Forget the complexities of connecting the R model to Tableau and finding a way to join or blend it with other data in Tableau. Forget finding a way to schedule R models to run to refresh data inside Tableau.  

The required R model can be built from inside the Tableau Report and the results can be analyzed on-the-fly!  Quite neat right? 

Tableau can integrate with both Python and R in this manner, but as per the title, this blog will be focusing only on Tableau – R integration in detail. 

So how does Tableau integrate with R?  It is through the Calculated fields. Tableau provides 4 scripting functions to pass R scripts and parameters to the R server, which then runs the scripts and returns the result. The 4 scripting functions are: 


These 4 functions differ in terms of the values they return. As evident in their names, they return real number, string, integer, and Boolean value respectively. 

Let us take an example, say, to create a Linear Regression line for a dataset- Percentage difference in access to electricity for Urban and Rural areas. Tableau does not have an inbuilt function to get the slope and intercept values so, we need to write a lengthy calculation using mathematical formulas. To avoid that, let’s use R. 

The dataset is as shown below:

Tableau Integration with R

R scripts in below manner can be passed to R server in a calculated field to create the Linear Model:

Tableau Integration with R

Using the calculated field in the visual will give us the linear regression line:

Tableau Integration with R

Before starting on the R modeling, Tableau Desktop and Tableau Server need to be connected to Rserve – The R server that Tableau uses (Rserve enables external applications to access and utilize R). This is a very simple process which can be completed as follows:

Configuring R in the system

  1. Download and Install R Studio.
  2. Install Rserve using the following steps.
  3. In the R console, enter the following commands:




Tableau Integration with R
Tableau Integration with R

Connecting with Tableau Desktop

  1. Connect Tableau Desktop to the R Server. In Tableau Desktop, go to the Help menu and select “Manage External Service Connection”.
Tableau Integration with R

5. Enter server names as Localhost or use “” and port as “6311”.

6. Click on the Test Connection button and ensure that it works correctly.

Tableau Integration with R
Tableau Integration with R

Remember that workbooks with R scripts can be opened in Tableau Server only when Tableau Server is connected to Rserve. Tableau Administrator needs to connect Tableau Server to Rserve.

Currently, only Tableau Desktop and Tableau Server have R integration. Tableau Online and Tableau Public users will not be able to make use of this feature.

The R integration is a powerful feature that enables Tableau users to harness the powers of statistical modeling from inside Tableau, but it has a few limitations. Only the 4 scripting functions can be used to interact with the R server and visualizations built-in R cannot be brought in via calculated fields. Also, if a calculated field using R scripts is used in another calculated field, both must be included in the visual for the second calculated field to work.

To learn more about Visual BI’s Tableau Consulting & End User Training Programs, contact us here.

Corporate HQ:
5920 Windhaven Pkwy, Plano, TX 75093

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192


Copyright © Visual BI Solutions Inc.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This!

Share this with your friends and colleagues!