Accessing the JavaScript API

If there are methods or objects you’d like to use that are not implemented in trexjacket, the entire Tableau Extensions API can be accessed directly from the tableau module. Documentation for the Tableau JS API can be found here.

For a more in depth conversation around accessing JS objects from Anvil, see the Anvil documentation.

To get a taste of what’s available, let’s take a look at the attributes of tableau.extensions.

# This import will be automatically added to your code in Anvil when you create a
# new Tableau Extension
>>> from anvil import tableau
>>> obs = [x for x in dir(tableau.extensions) if not x.startswith('_')]
>>> print(obs)

['constructor', 'createVizImageAsync', 'dashboardContent', 'dashboardObjectId', 'environment',
'extensionImpl', 'get', 'initializeAsync', 'initializeDialogAsync', 'keys', 'setClickThroughAsync',
'settings', 'ui', 'workbook']

The corresponding Tableau extension documentation (see here) lists the following:

https://extension-documentation.s3.amazonaws.com/guides/js_api/tableau_doc.PNG

Note that the properties and method names in the above image are also included in dir(tableau.extensions), and these methods can be called from within Python. For example, taking a look at dashboardContent returns:

>>> from anvil import tableau
>>> print(tableau.extensions.dashboardContent.dashboard.objects)

[<e (native JS) proxyobject>, <e (native JS) proxyobject>, <e (native JS) proxyobject>,
<e (native JS) proxyobject>, <e (native JS) proxyobject>, <e (native JS) proxyobject>,
<e (native JS) proxyobject>, <e (native JS) proxyobject>, <e (native JS) proxyobject>]

These proxyobject can be interacted with in Python, usually by accessing their attributes by name. These proxy objects is what trexjacket wraps, to make building extensions quick and easy. For example, according to the documentation, dashboard.objects is an Array of DashboardObject. Each of these objects has properties such as name, type, and isVisible. Let’s see what happens when I try to access these properties from Python.

Note

The autocompleter in Anvil will help you out even when navigating through the underlying methods of the tableau module from anvil.

>>> from anvil import tableau
>>> objs = tableau.extensions.dashboardContent.dashboard.objects
>>> for x in objs:
...     print(f'name: {x.name}, type: {x.type}, isVisible: {x.isVisible}')

name: Viz, type: worksheet, isVisible: True
name: Tiled, type: blank, isVisible: True
name: Underlying Data Demo, type: extension, isVisible: True
name: Tiled, type: blank, isVisible: True
name: Vertical, type: blank, isVisible: True
name: Horizontal, type: blank, isVisible: True
name: Ship Mode, type: quick-filter, isVisible: True

Nice! Even though I got a list of proxy objects, I am still able to access their properties and even methods using Python code.