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 Main.

https://extension-documentation.s3.amazonaws.com/tutorials/chat/helloworld.gif

Open up Main and click on the “code” button at the top. At the code near the top of the form, let’s use get_dashboard to create an instance of our dashboard and print a message to the console:

 1from ._anvil_designer import MainTemplate
 2from anvil import *
 3from anvil.tables import app_tables
 4from anvil import tableau
 5
 6from trexjacket.api import get_dashboard
 7dashboard = get_dashboard()
 8
 9class Main(MainTemplate):
10  def __init__(self, **properties):
11    self.init_components(**properties)
12    print('Hello, World!')

Tip

dashboard is an instance of the Dashboard class, which gives you access to all your dashboard elements, things like filters, parameters, datasources, and marks!

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).