I love data and I’m always searching for new ways to make more data easily accessible to the Tableau user. In this example, I’ll demonstrate how to access Internet data via a REST API. It might seem slightly complicated, but it’s actually quite easy to reproduce for your real needs. However, should you have any complex and specific needs, Interworks consultants will be happy to help… we love challenges as much as we love data!
You’ll find a lot of websites providing data which you could use in your analysis (weather, stock exchange, airline traffic…). For this example we will build a visualisation based on Decaux Velib data. Velib is an automated bike rental service. Starting in Paris, it is now available in many other cities. As a Velib service user, you may be in search of an available bike around you OR in search of an available stand to return a rented bike.
This dashboard shows all the Velib stations in Paris; a color coding shows the availability level (of bikes or free stands). Clicking on a station will display a Google street view of the station surrounding.
Here is the finished dashboard :
The steps for this example are:
- Use a Python program to connect to Internet data provider and get the data via a REST API
- The same Python program will create a Tableau data extract file containing the data in a usable format using an API provided by Tableau (Tableau Data Extract API)
- Tableau Desktop will then be used to visualize the data from the data extract file
Important: the Tableau Data Extract API only works on a Windows based PC, not on Mac.
This example uses Python as a programming language but the same result can be achieved using C/C++ or Java.
Things to install before we start:
- Tableau desktop version 8 or 9
- Python can be downloaded from here: https://www.python.org/downloads/windows/, pick up the latest Python 2 release and install it
- Tableau Data Extract API downloadable here: http://www.tableausoftware.com/data-extract-api. Select 32bits or 64bits according to your Windows version. Just download the file for later use.
- Optional: a Google Chrome application called « Postman » to verify the JSON source before using it; accessible from the Chrome Web Store here: https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en
Step 1: Register at Decaux Open data
It is free – Decaux will give you a personal API key, which you will need to access real time data.
The registration process may be different for another data provider but you will end with an API key in most case.
Connect to this URL and follow the registration instructions: http://developer.jcdecaux.com
Step2 (optional but safer): Test your connection/key
From Google Chrome, launch the Postman application, enter the following URL:
and click on “Send”; you should get a result like this, displaying the data in a JSON format :
The available data is displayed in JSON format; note that “lat” and “lng” are part of a group called “position”, this is important when referencing a data in the Python script.
Now we know the API key is valid and we have a good view of the provided data structure
Step 3: Python modules
Python comes with a set of standard modules (equivalent to functions or procedures) and additional modules can be added by installing them to an existing Python installation.
3.1/ Download the Tableau Data Extract API for Python (download link provided in the prerequisite part of this document) and install it within Python 2.7
- After downloading the zip file, unzip it to the “
- Open a command line window (cmd.exe)
LibDataExtract-xxx (created by the unzip)
- python setup.py install
3.2/ The program also needs an optional Python module (called requests) to be installed (no need to download it):
- open a command line window (cmd.exe)
- pip install requests (this will download and install the module)
Step 4: The Python script
The Python script (.py file to be extracted from the attached zip file) will:
- Connect to the Decaux Open Data website
- Read information for Paris bike rental stations
- Create a Tableau Extract called velib.tde
Modify the script to insert your Decaux API key where indicated, on line 40, before using it.
The script contains descriptions of the different tasks.
To launch the script, use the following Windows command line:
Ratinger Straße 9
Geschäftsführer: Mel Stephenson
Telefon: +49 (0)211 5408 5301
Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072