Integrating Tableau with R for Data Science
Integration of Tableau with R
R is a popular open-source environment for statistical analysis. Tableau Desktop can now connect to R through calculated fields and take advantage of R functions, libraries, packages and even saved models. These calculations dynamically invoke the R engine and pass values to R via the Rserve package, and are returned back to Tableau.
Tableau Server can also be configured to connect to an instance of Rserve through the tabadmin utility, allowing anyone to view a dashboard containing R functionality. Combining R with Tableau gives you the ability to bring deep statistical analysis into a drag-and-drop visual analytics environment.
Tableau – R Integration
Together, R and Tableau could be extremely useful in today’s data science arena as together it can unravel any organization’s end to end information discovery needs.
R has become one of the foremost widely used statistical software packages among statisticians and researchers since it provides more than 10000 specialized packages. Tableau takes only seconds or minutes to visualize using a simple to use drag-and-drop interface.
Here in this blog, we will go through the steps of integrating R and Tableau.
Prerequisite to follow below steps: R and tableau is already installed
Inside R software, install Rserve package with below command.
Once the installation for the package is complete, we run the package with the command below.
This will start a Server in the background irrespective of whether R console is open.
Now we move to Tableau to perform connection to the server we just started.
While startup page, go to Help→ Settings and Performance → Manage External Service connection.
This will prompt a small window where server name is localhost and port 6311 is to be set.
Press test connection to get the successful message. And then press OK.
This proves the connection to Rserver is complete.
We will now see a small example if it works for us.
Taking a small sample data inside Tableau.
Importing Data in Tableau
You may see sample data form a tabular structure.
Now change the tab from Database to Sheet.
Now we see how the calculation happens with the help of Rserver.
Problem Statement: Calculate Total Expense done.
Go to Analysis Tab and select Create-Calculated-Field
Now Give a Name to Field.
As I have given TolalExpense and click Apply.
Now write a Script which will run in R.
For my case the Script is:
SCRIPT_INT( ” ToExp <- .arg1 ” , SUM([Jan]+[Feb]+[Mar]) )
Explanation: we have SCRIPT_INT as the script will return integer type.
Test between “ ”, is the script running in Rserver. And .agr1 will take function SUM as value to process data.
A message displays when we Apply. Our script is pushed to Rserver and checked if the calculation is valid or not.
Press OK to save the script and come back to Tableau to visualize our query.
Drag and Drop the Fields to Visualize data. Also, we can see our solution has created a field which we can drag and compare with other fields.
Solution: Total Expense is 75000
Hope this clears how to run Rserver for calculation and Tableau to visualize data together.
Please share you feedback below in the comment box to stay connected. And finally let’s be friends.