Making Vega-Lite Visualizations from Tableau REST API Pulse Methods
This walkthrough will show you how to create a Vega-Lite visualization from a Pulse Metric using Tableau’s REST API. All the code for this walkthrough is available here on Google Colab. If you want a video walkthrough of the code, you can find it here. Below is an image of the viz we will be making.
For background, Vega is an open source visualization tool based on the late Leland Wilkinson’s Grammar of Graphics. Like Tableau, creating visualizations in Vega or Vega-Lite relies on defining a visual encoding for marks (e.g. bars, lines, scatter point, etc.), as well as establishing a mapping between fields in your data and the X and Y axis of the visualization.
In the screenshot below, you can see the similarities between how Vega-Lite creates a scatter plot and how Tableau does:
This “grammar” approach to graphics is what gives Vega and Tableau so much flexibility and expressiveness when it comes to making complex visualizations.
Tableau Pulse REST API Walkthrough
*In order to follow along, you will need to have admin access on a Tableau Cloud site with Pulse enabled.
The Tableau REST API has a set of Pulse methods, one of which is Generate springboard insight bundle. The springboard insight bundle contains a json specification needed to generate a Vega-Lite viz for how your Pulse metric changes over time.
There are a few steps we need to take before we’re ready to call the generate insight bundle function. These steps include the following:
Authenticate into Tableau’s REST API using Connected Apps
Grab the ID for a Pulse metric that a given user is subscribed to (in our code, we just return the 1st one)
Grab the corresponding metric definition
Parse out certain elements from the metric definition to create a new json that will be used as an input for calling the generate insight bundle function (this is the least intuitive step)
Parse out the ‘viz’ element of the springboard response and copy/paste that into the Vega-Lite online editor
Step 4 is tricky and the Tableau documentation addresses how funky this json input is. The docs recommend going into the network tab of developer tools in your browser so you can see how this json input is shaped.
Hopefully in the future, you will be able to simply pass the metric definition as-is into the generate insight bundle function.
If you’ve followed along and pasted the ‘viz’ component of the springboard bundle into the Vega-Lite editor, it should look something like this:
Again, here are links to the code and a video walkthrough. Thanks for reading!