Tableau Integrations for Improved Workflow

March 11, 2022

The world seems so much better when we can use our existing tools and software inside the mission-critical applications. That was true for integrating Microsoft Excel inside databases or PowerPoint presentations and that is true for modern BI tools as well to integrate existing data science workflows for improved productivity. This way, the businesses can tailor the software to their problem, using already existing processes, saving up time, money, and annoyance of starting something from scratch. 

Tableau has got several integrations to make things easier for analysts, data scientists, decision-makers. Here in this article, we will talk about Tableau-Python integration and Tableau-Slack integration.

Tableau-Python Integration 

TabPy is an Analytics Extension from Tableau which enables a user to execute Python scripts using Tableau. Using TabPy, Tableau can run Python script on the fly and display the results as a Visualization. Users can control data being sent to TabPy by interacting in their Tableau worksheet, dashboard, or stories using parameters. 

TabPy expands Tableau’s capabilities by allowing users to execute Python scripts and saved functions via Tableau’s table calculations. When you use TabPy in Tableau, you can define calculated fields in Python, and leverage many machine-learning libraries right from your Tableau visualizations. 

This Python integration in Tableau enables powerful scenarios. For example, it takes only a few lines of Python code to get the sentiment scores for reviews of products sold at an online retailer. Then you can explore the results in many ways in Tableau. 

Need for Python in Tableau: 

Not every tableau user will need python. Tableau is capable enough in itself for much of the visualizations including clustering. But it makes using machine learning models easy to use for business users.  

Say you need to do sentiment analysis of your product. Rather than devising something from scratch, it would make sense to use the Python libraries to do that. So you connect Tabpy, create a calculated field, write your script in python, and voila! You have your model available as a calculated field. You can use multiple models like this or maybe even create parameters. 

But why visualize in Tableau when Python already has libraries for Visualization? Because it’s easy to implement those ML models in Tableau without the need for the business users to know it, just like another ‘measure’ or ‘dimension’. Complexity is hidden behind abstraction and all the data updates and workflows that you set up in Tableau, will automatically be implemented. 

If you or your company is already using Tableau for their visualization needs, then this makes tableau a complete package. 

Common business use-cases of Tabpy:

Lead scoring: Create a more efficient conversion funnel by scoring your users’ behavior with a predictive model. 

Churn prediction: To predict churn and non-churn customers, the PyCaret package can be used with the Naive Bayes Classification model. You would write the code in python, save it as a pickle file, and then copy it as the calculated field in tableau. You can thus estimate the probability of customer churn. 

Sentiment Analysis: In sentiment analysis, we try to determine the emotion of a text. In simple words, sentiment analysis works by comparing each individual word of the given text to a sentiment lexicon that has words with predefined sentiment scores. 

Using published models has several benefits. Complex functions become easier to maintain, share, and reuse as deployed methods in the predictive-service environment. You can improve and update the model and code behind the endpoint while the calculated field keeps working without any change. And a dashboard author does not need to know or worry about the complexities of the model behind this endpoint. 

How to use python inside Tableau 

Steps to get TabPy up and running

1. If not already installed, Go to pythons website, download and install Python3

2. Then create a virtual environment in python,

a. conda create –name nameofyourvirtualenv

b. The benefit of creating a virtual environment is that you can do anything without making systemwide changes.

c. You can have multiple virtual environments to run multiple workflows.

3. Upgrade pip package manager

a. python -m pip install –upgrade pip 

4. Then, Download and install the Tableau Python server (Tabpy) –

a. pip install tabpy

b. If it does not happen, then

c. pip3 install tabpy


5. Run Tabpy in your terminal by typing tabpy

a. Your server is running on port 9004

6. Open Tableau, go to Settings >> Manage Analytics Extension Connection >> Tabpy

7. Then Setup the server with the name localhost and port 9004

8. Voila! TabPy is ready to use in Tableau

Now you can write code directly as Tableau calculated fields. The code then will be executed in the TabPy server.

What if you want to use it not just yourself but company-wide? Then hosting the server on your local machine wont work. But the good news is, you can set up on the cloud (EC2 in AWS or Virtual machines in Azure or Google Compute Engine in GCP). Thus, once you start the server, any Tableau user in your company can make use of it.

Below are the steps to do it in AWS:

1. Go to AWS Services >> All Services >> Compute >> EC2

a. If you already don’t have an instance running, then launch the instance

2. Choose any distribution (Ubuntu recommended),

a. Select instance type as t2.micro, or depending on your workload.

b. Select storage 

c. No need for tags, leave it blank.


3. For security configuration,

a. Choose custom TCP rule with port 9004. IP you can ask your system administrator for it.


4. Next, create a keypair and name it

5. Then download the .pem key file


6. Click on the Launch Instance button 

Then, you can use this tutorial to connect EC2 to your local computer. 

And you can follow the steps above to install and launch Tabpy but this time itll be running in the cloud.

Using python scripts in Tableau

We have TabPy up and running now, so let me write the steps for sentiment analysis as an example.

1. Upload the data in Tableau

2. Open the sheet, create a calculated field

3. In the calculated field, write the script


          import nltk

          from nltk.sentiment import SentimentIntensityAnalyzer

          text = _arg1

          scores = [] 

          sid = SentimentIntensityAnalyzer() 

          for word in text:

              ss = sid.polarity_scores(word)


          return scores 



4. There are 4 types of script functions in tableau, one for each type of data:

* SCRIPT_STR for strings / text

* SCRIPT_INT for integers / whole numbers

* SCRIPT_REAL for real numbers/decimal numbers 

* SCRIPT_BOOL boolean / true or false

5. You can then have the visualization

This way you can use TabPy for advanced data analytics by using python inside tableau.

Tableau-Slack Integration 

Tableau has always looked for ways to make data more accessible to a greater number of people across an organization, the ability to query your data inside Slack by asking questions using natural language. This means, asking a question in plain English and you will get an interactive chart.

Tableau for Slack makes it easy to stay up-to-date on your data right where collaboration happens in Slack. Now, you can see Slack notifications for changes to your data and dashboard activities in Tableau. 

Teams can get Slack notifications for: 

  • Data-driven alerts when data meets a specified threshold
  • Sharing when a Tableau asset has been shared with you
  • Comments when you are @mentioned in a comment

Admins can easily connect their Tableau site to a Slack workspace to enable these features for their entire organization. 

Someone will notice something interesting in the data and can instantly send a message in the Slack channel for that insight, questions get asked (and answered) quickly and your data is being used the way it should be: to take action, to drive decisions, and to make everyone smarter. 

Stay on top of your data, without ever leaving your slack channel. Get data-driven notifications when data meets specific thresholds or getting mentioned in a comment. You can share AI predictions with your entire team. 

This way you can make speedier decisions. And if you want to dig deeper, you can always go inside your Tableau dashboard. 

Visualizations have made their place in team messaging apps be it Tableau for Slack or PowerBI for teams. Teams are aggressively using visualizations to gain insights from the data to monitor team-specific KPIs and set the goals accordingly.