Recently, Tableau released an exciting feature that enhances the capabilities of data analytics: R integration via RServe. By bringing together Tableau and R, data scientists and analysts can now enjoy a more comprehensive and powerful data science toolbox. Whether you’re an experienced data scientist or just starting your journey in data analytics, this tutorial will guide you through the process of integrating R with Tableau.
Step by Step: Integrating R in Tableau
1. Install and start R and RServe
You can download base R from r-project.org. Next, invoke R from the terminal to install and run the RServe package:
> install.packages("Rserve")
> library(Rserve)
> Rserve()
To ensure RServe is running, you can try Telnet to connect to it:
Protip: If you prefer an IDE for R, I can highly recommend you to install RStudio.
2. Connecting Tableau to RServe
Now let’s open Tableau and set up the connection:
3. Adding R code to a Calculated Field
You can invoke R scripts in Tableau’s Calculated Fields, such as k-means clustering controlled by an interactive parameter slider:
4. Use Calculated Field in Tableau
You can now use your R calculation as an alternate Calculated Field in your Tableau worksheet:
Feel free to download the Tableau Packaged Workbook (twbx) here.
Connect and Stay Updated
Stay on top of the latest in data science and analytics by following me on Twitter and LinkedIn. I frequently share tips, tricks, and insights into the world of data analytics, machine learning, and beyond. Join the conversation, and let’s explore the possibilities together!
Blog post updates:
- Tableau 8.1 screenshots were updated with Tableau 10.0 (preview) screenshots due to my upcoming Advanced Analytics session at TC16, which is going to reference back to this blog post.
- This tutorial is featured in my new book Visual Analytics with Tableau. Get your copy!