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:

https://extension-documentation.s3.amazonaws.com/media/getting-started-demo.gif

To get started, first:

  • Click here to open a starter Anvil app to build off of.

  • Click here to 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:

  1. Click the green “Test in Tableau” button in the top right.

  2. A popup will appear, click “Download the manifest file” and the .trex file should download.

In Tableau:

  1. Go to your dashboard, drag and drop the “Extension” object wherever you’d like.

  2. In the bottom left of the alert that appears, select “Access Local Extensions” and locate the .trex file from step 2.

https://extension-documentation.s3.amazonaws.com/media/download_trex.gif

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:

  1. Get the current Tableau dashboard using get_dashboard. This returns a Dashboard object and contains many useful attributes and methods such as datasources, filters, parameters, and worksheets.

  2. Bind the show_selections method to the selection_changed event of the Tableau dashboard using register_event_handler. The selection_changed event triggers show_selections whenever 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!
https://extension-documentation.s3.amazonaws.com/media/getting-started-demo.gif

Additionally, output from the print statement appears in the Anvil IDE:

https://extension-documentation.s3.amazonaws.com/media/output_in_anvil.PNG

Eager to keep building? Check out the Building a Chat Extension tutorial next!