Chapter 2: Hello World!
Now that we’ve added the trexjacket
dependency and connected our Anvil app to our Tableau Dashboard using a .trex
file, let’s use Anvil X to access the dashboard from Anvil by adding some code to Form1
.
Open up Form1
and click on the “code” button at the top. At the code near the top of the form, import get_dashboard
from trexjacket.api
import get_dashboard
and create an instance of the dashboard in the form:
1from ._anvil_designer import Form1Template
2from anvil import *
3from anvil import tableau
4
5from trexjacket.api import get_dashboard
6dashboard = get_dashboard()
7
8class Form1(Form1Template):
9 def __init__(self, **properties):
10 self.init_components(**properties)
11 print('Hello, World!')
Tip
dashboard
is an instance of the Dashboard
class, that has gives you access to your dashboard elements, things like filters, parameters, datasources, and marks on the dashboard.
After adding the Form1
code, let’s see our changes in action. We’ve already added our Extension to our dashboard, but because we’ve changed our app in Anvil we’ll need to reload the extension in Tableau. To do this:
Click inside your extension inside Tableau and click the grey, downward facing caret icon
Click “Reload”
Once you’ve reloaded your extension, you should see the output of your “Hello, World!” statement in the “Tableau Output 1” pane inside Anvil (see gif).