Clojure FOR EVERYONE Tableau
Mulitplayer Blackjack Game in Tableau using ClojureScript
November 21, 2015
, , , , , , ,

This year I had the honor to present at Tableau Customer Conference in Las Vegas together two hyper-blackbelt-jedi masters: Michael Kovner and Russell Christopher. The track’s name was “You did WHAT with the Javascript API?!” and as you can imagine we had some heavyweight stuff to throw. One of my API example was a complete multiplayer blackjack game using Tableau Public as gfx engine and clojure/script as backend and frontend programming language.

Let’s see how I built it from Tableau and programming perspective. But first… the game.

The Game

It’s a classic black jack game: all players (well, maximum two in our case) plays against the dealer. First the players hit until they’re fine with their cards, then stand. Dealer must always hit if his score is less than 17, otherwise stand. Now imagine this in Tableau. (But unlike vizpainter’s black jack game the logic here is outside of tableau).

Since the presentation was recorded the easiest way is to watch this video:

You can try it here as well:

Now a couple of things (disclaimer or user’s guide):

  • When the page loads you have to add your name and chose your role (player 1 or player 2)
  • For new game click “New”
  • Hit is hit, stand is stand. If two of you are playing then both of you need to stand before the dealer reveals his cards.
  • If anyone logs in with the same role in the meantime fun things will happen. You might be kicked off or other unexpected things might arise (like switch to cooperative mode)


Details, Tableau

How does this work? Since I built the whole game in less than a day you can imagine: it’s not too complex. The game area is a dashboard. On the top everything is parameter driven: the opponent’s name, score and bar chart with score all rely on parameters.

Tableau Game area - Complete Dashboard

Tableau Game area – Complete Dashboard

The cards are coming from two separate sheets. Those sheets are using the same data set: numbers from zero to 851. The first digit (after left padding with zero) shows the location in hand while the second and third describes the card itself (it can be empty, a standard card from 52 cards deck or a face down card).

Every card has its location and card identifier. This used to position it to a scatter plot using custom shapes

Every card has its location and card identifier. This used to position it to a scatter plot using custom shapes

The viz is shape based with the card position on the columns shelf. Shapes are custom, each one for a card type.

You can have a look on the raw tableu workbook here: . Feel free to download and have look in it.

Even more Details, Clojure, ClojureScript

Okay, let’s switch to hardcore mode. First of all all sources are on github, but this is not everything. Since I used clojure docstrings and comments I was able to generate developer docs using Marginalia (not the original, but Michael Blume‘s fork). Marginalia produces similar output as Docco for CoffeScript: on the left side you can see your docstrings while the right side contains the code. In my opinion this is the best approach: usually I start reading the source codes before any developer documentation but here I can read both in the same time.:

This is how the generated documentation looks: code and explanation in the same line.

This is how the generated documentation looks: code and explanation in the same line.

You can read the generated documentation here:


My main goal was to show how multiple people can see the same dataset from different angles from multiple locations. Thus, I needed a server that receives interactions from users, interprets them and sends back the shared state. And this needs to be real time: if one player hits a card then the other should see it immediately (like a push notification based tableau data change). This just cries for web sockets that allow to send and receive asynchronous messages between browsers and server.

I decided to put everything tableau related to the tableau namespace on client side (=clojurescript, running in browser), blackjack game related functions went to blackjack namespace on server side while client-server communications are in client and server on their respective sides. The client does nothing just sends the click events to server (logon, hit, stand, new) and renders the tableau report when the server asks for it.

The server sends the full state information always in the same format. It has the player names and scores, their cards, status messages. When it arrives to client I just use the Tableau JS API to set the correct filters and parameters. Tableau JS API is smart enough to not update the dashboard if I set the same filters again and again.

For managing websocket I have used sente which provided a core.async  compatible interface to send and receive messages. It was cool.

Avoiding “callback hell”

Last time when I built my snake game I used asynchronous messaging to notify the game engine when the tableau visualization loaded. This time I used a different method to avoid nesting callbacks and have dependency between modules (by design your tableau workbook should not know about your game logic and your game logic should not know about your tableau workbook). I end up with using atom . When the workbook has loaded it changes its state to loaded. Then, other modules can sign up to this atom’s changes.

When the viz is ready just send a “load” message to the server and start the fun!


There is always a purpose. With this mini-project my goal was to showcase that with Tableau JS API your only limitation is your imagination. It was a few hours of work to build an application where different users were able to see and understand play with the same set of data, together but from different perspectives. Or if you logon with the same username from multiple devices and change something it will visible on the other device immediately. Again, only matters of few hours of work.

It’s fun and easy.


Tamás Földi

Related items

/ You may check this items as well

sync frelard

Tableau Extensions Addons Introduction: Synchronized Scrollbars

At this year’s Tableau Conference, I tried t...

Read more

Tableau External Services API: Adding Haskell Expressions as Calculations

We all have our own Tableau Conference habits.  M...

Read more
Scaling Tableau Image

Scaling out Tableau Extracts – Building a distributed, multi-node MPP Hyper Cluster

Tableau Hyper Database (“Extract”) is ...

Read more