Table Extensions
Table Extensions allow you to create data tables with an analytics extensions script. You can write a custom TabPy or Rserve script and optionally add one or more input tables. Table extensions are supported by Tableau Cloud, Tableau Server and Tableau Desktop. This document focuses on Tableau Cloud.
Note: Similar to a live connection, the Table Extension refreshes every time you open up a workbook or refresh a data source.
Benefits
Table Extensions have the following benefits for both new and experienced users.
Easily integrate scripts or advanced functions into Tableau
Easily drag data from Tableau data connections as input into scripts
Low code editor makes adding code to data sources easy
- Integrates with Data Guide and Explain Data
Integrates with TabPy, Rserve and other analytics extensions
- Results can be used to construct dashboards or visualisations
Prerequisites
Before you can use table extensions, you must complete the following list.
- Open a data source in Desktop or Web Authoring.
- Configure an analytics extension
- For steps to configure analytics extension connections, see Pass Expressions with Analytics Extensions.
Create a Table Extension
To create a table extension, complete the following steps.
- Open a published workbook.
- Open a data source or create one.
- Under connections, choose New Table Extension.
- Drag it into the data model.
(Optional) Drag tables from the data connection into the table extension pane to use as input into your analytics extensions script or function.
By default data from Tableau is passed to the analytics extension and defined as the
variable _arg1
, a dictionary-like structure such as:{‘colum_name’: [1,2,3], ‘column_name_2’: [3,4,5]
Python example: The input data could be converted to a pandas dataframe using the following.
import pandas as pddf = (pd.DataFrame(_arg1))
When using RServe, the input data is defined as the variable .arg1 and the data type are a named list of lists.
For supported relational data sources, you can use Custom SQL as an input into a table extension. When parameters are used in the Custom SQL query, changing the parameter causes the query to rerun and the script to recompute. This creates a path to dynamically update parameters in a dashboard and filter or otherwise pass values to the table extension script.
In the Script area, enter your script or function call. The script must return a dictionary or list of lists, essentially a JSON object. A script for RServe must return a data.frame or list of named lists while the script for Python must return a dictionary.
Python example: We use the following explicit return command.
return df.to_dict(orient='list')
- Select Apply to run the script.
(Optional) If you’re relating the table extension to another table in the data model, define the relationship between at least one field in each table. If the fields have the same name, this may happen automatically.
- Choose Update Now and the results appear in the Output Table tab.
Note: Table extensions don't support directly calling TabPy endpoints if TABPY_EVALUATE_ENABLE is disabled in TabPy.
Note: If you don't define a relationship to a table in the data model, the Input Table tab is empty and will display the message ‘Data preview unavailable’.
- (Optional) In the Name field, enter a unique name for your table extension.
- Go to the Sheet tab to start exploring and visualising the data. Results from a table extension functions like any other data in Tableau queried from a flat file or relational source.
- Publish the workbook to share it. The publishing destination, Server or Tableau Cloud, must have an analytics extension of the appropriate type enabled and configured.
Troubleshooting tip: Errors from analytics extensions will be surfaced in a Tableau error message if there’s a problem executing the script. If your table extension is hitting an error, ensure all code and formatting is correct and try using the circular Refresh Data Source button, located next to the Save button, or click Apply again.
Table Extensions vs Analytics Extensions
While some of these products aren't related, table extensions and analytics extensions share several features. The table extensions feature relies on a connection with analytics extensions to work. Let's break down each feature.
Dashboard Extensions
Dashboard extensions allow custom web applications to be added to dashboards using the Dashboard Extension SDK, however, this extension type isn’t related to table extensions.
Table Extensions
The Table extensions feature lets you create a table in a data source that can send data and a script to your analytics extension and return a full table of arbitrary shape as a result. The returned results are displayed as a table in the data model in the Data Source tab and as measures and dimensions in the workbook.
Analytics Extensions
The Analytics extensions feature allows you to extend Tableau calculations with programming languages like Python, external tools and external platforms. After you create a connection to an analytics extension, you can communicate with your external server through calculated fields called SCRIPT_X or MODEL_EXTERNAL_X, where X is the data type of the expected return values. For more information, see Pass Expressions with Analytics Extensions.