TabPy gives the power to leverage many Machine-Learning libraries.
TabPy permits Tableau to execute python code remotely.
It comprises of two Parts:
- Tornado site package which is responsible for executing the python code remotely through REST API’s.
- Tools Library used for endpoint deployment based on the python functions used.
Download and Install Tableau Desktop
- Go to https://www.tableau.com/products/desktop
- Click the “Try Now” button
- Download the trial Pack available for 14 days trial period, by providing your email address.
- The latest tableau version will get downloaded.
- Run the extension file by double clicking it and accept the terms and condition.
- Click Install
- Once Installed, open the Tableau desktop, and fill in the details on tableau registration form.
- Click the “Start Trail Now” button. The Tableau Desktop screen will get opened. Now, we are done with Tableau desktop Installation.
Download and Install Python
- Go tohttps://www.python.org/downloads/.
- Download the latest version and double click the Python extension and install the python.
- Add the python path and python script path to the system environmental variable as shown below:
4. Open the command prompt and type the command.
python --version. If you see the version downloaded, then python is working fine.
If you face error like below Traceback (most recent call last): File "tabpy.py", line 279, in class EndpointsHandler(ManagementHandler): File "tabpy.py", line 287, in EndpointsHandler @tornado.web.asynchronous AttributeError: module 'tornado.web' has no attribute 'asynchronous' Downgrade the tornado version to pip install Tornado==5.1.1
Connecting Tableau and Tabpy Server
- Open the Tableau Desktop
- Under Help dropdown, choose Settings and Performance and then click Manage Analytics Extension Connection.
- In the Analytics Extension Connection dialog box,enter the following data.
- Under Select an External Service, choose TabPy/External API
- Enter localhost in Server field.
- In Port, type 9004
- Clicking the Test Connection will show a message like “Successfully Connected to external service”.
Building Worksheets in Tableau Desktop
Note: Used Sample superstore dataset for this demo purpose.
Scenario: Find out the states with Profit is less than zero (Profit < 0)
- Connect to the dataset by clicking the Text file under To a file and choose the sample superstore dataset which is in (.csv) format. If it is (.xls or .xlsx), connect to Microsoft excel under To a File.
- Next, create the Calculated field as shown below using python script:
3. Now, Drag State and calculated field created named here as (Profitable) to the Rows Shelf.
4. Drag Profit under measures to the Columns shelf
5. Drag Calculated Field (Profitable) to the Color Marks.
Now, we can get the state name with profit < 0 and they are differentiated based on color as well as shown in the image below:
Note: The output from the calculated field is either True or False since we used Boolean script (SCRIPT_BOOL). Please refer to the image attached above.
Limitations of TabPy
- While extracting data, Python generated data will not be extracted.
- When working with large dataset, we must wait for more time for every time the script runs.
- To run the script, we should add it to the view.