Getting Started
Let’s build a simple Tableau extension that displays the summary data from Tableau when a user clicks a bar in a bar chart. When we’re done we’ll have something like this:
To get started, first:
Click
hereto open a starter Anvil app to build off of.Click
hereto download the sample Tableau workbook that this guide will use.
Download and add the trex file to Tableau
In order to add an extension built in Anvil to a Tableau dashboard it needs to be added to the dashboard using a .trex file. The trex file is first downloaded from Anvil and then dropped in to your Tableau dashboard.
In Anvil:
Click the green “Test in Tableau” button in the top right.
A popup will appear, click “Download the manifest file” and the
.trexfile should download.
In Tableau:
Go to your dashboard, drag and drop the “Extension” object wherever you’d like.
In the bottom left of the alert that appears, select “Access Local Extensions” and locate the
.trexfile from step 2.
Write some code
Now that we’re connected to our dashboard let’s add some code to our starter app. Click MainForm on the left and open the code by clicking the button labeled “Code”. Then add the following code:
1from ._anvil_designer import MainFormTemplate
2import anvil
3
4from anvil import tableau
5from trexjacket.api import get_dashboard
6
7class MainForm(MainFormTemplate):
8 def __init__(self, **properties):
9 self.init_components(**properties)
10 self.dashboard = get_dashboard()
11 self.dashboard.register_event_handler('selection_changed', self.show_selections)
12
13 def show_selections(self, event):
14 marks = event.worksheet.get_selected_marks()
15 print(marks)
16 self.label_output.text = str(marks)
We do 2 things in the code above:
Get the current Tableau dashboard using
get_dashboard. This returns aDashboardobject and contains many useful attributes and methods such as datasources, filters, parameters, and worksheets.Bind the
show_selectionsmethod to theselection_changedevent of the Tableau dashboard usingregister_event_handler. Theselection_changedevent triggersshow_selectionswhenever the user selects / unselects marks.
Let’s reload our extension since we’ve made changes. In Tableau, click inside the extension you dropped in and click the grey carat icon. Then select “Reload”.
Click a mark on the dashboard and congrats, you now have a working Tableau extension!
Additionally, output from the print statement appears in the Anvil IDE:
Eager to keep building? Check out the Building a Chat Extension tutorial next!