Introduction
Tableau is a business intelligence software that helps users see, understand and act on data. Tableau relies on a drag and drop user interface that allows users to build reports and visualizations with ease. Though Tableau is powerful in reporting and visualizations, it falls short when it comes to statistical computations – a deficit that can be enhanced by leveraging other tools such as R, MATLAB, and Python.
R is a programming language for statistical computing and graphics. It is built with statisticians in mind and packed with hundreds of libraries capable of solving complex statistical work such as modelling, spatial and time-series analysis, classification, statistical tests and more. R is widely used in data science by statisticians and data scientists for data analysis and statistical modelling.
In this short article, I will be demonstrating how you can bring the power of R to Tableau by integrating the two - enabling you to not only build powerful visualizations and reports but also solve complex problems that require statistical skills and resources.
Integrating Tableau and R
To integrate Tableau and R,
Step 1: Download and install R on your machine.
Step 2: Download and install Rserve.
In the R console, enter the following commands.
install.packages (“Rserve”)
library (Rserve)
Rserve ()
Step 3: Connect Tableau to the R Server. Once Rserve is installed, open your Tableau Desktop application, and go to Help menu >> Settings and Performance >> Manage Analytics Extension Connection…
Enter server name as “localhost” (or “127.0.0.1”) and port as “6311”.
Next, click ‘Test Connection’ to ensure everything works smoothly.
You should see successful connection message.
Step 4: Now you can start using R scripts in Tableau by creating calculated fields that utilize the SCRIPT_*** functions to make R functional calls.
Note, there are four built-in Tableau Desktop functions that are used to call specific R models and functions. They include.
SCRIPT_REAL ()
SCRIPT_STR ()
SCRIPT_INT ()
SCRIPT_BOOL ()
These functions are distinct only in the type of result they return – that is a real number, a string, an integer, and a Boolean respectively.
For Example
Using the SCRIPT_REAL () function I can multiply the variable “Test 1” by 100 using the following calculation.
Again, using the SCRIPT_REAL () function I can compute the p-value for a correlation test and t-test between ‘Test 1’ and ‘Test 2’ values using the following calculations.
Computing correlation p-value
Computing t-test p-value
Add the three calculations to the view to see the results.
(Though, you could easily multiply ‘Test 1’ values by 100 within Tableau… Computing the p-value for a correlation test or t-test would require capabilities not within reach in Tableau. Computing powers which you can tap by integrating Tableau with other tools such as R and Python).
Conclusion
I hope this article was helpful to you. If you wish to receive more Tableau tips and tricks, kindly join our mailing list by subscribing below.
If you like the work we do and would like to work with us, drop us an email on our contacts page and we’ll reach out!
Thank you for reading!