This week we took at look at Sets and Set Actions in Tableau and how we can use these to enhance the user experience on our dashboards.
For the purposes of this post, I will demonstrate using Sean Miller’s Workout Wednesday Viz to show how the user can interactively add and remove values from their selection.
Creating the set
In this example, we take our States field and create a set by right clicking it in the fields list to the left. Make sure you call it something imaginative yet recognisable, like ‘State Set’.
Great, that’s the first part done. Take a little break and come back for the next step when you’re ready.
The Selection Map
A nice, visual way of having the user select which states they want to include in their selection is by allowing them to click on the state to select it.
Following on from above, drag your States field out onto Detail on the Marks card and your State Set to Color. Make sure the latter is set to ‘Show In/Out of Set’ by using the dropdown arrow.
After a bit of color formatting and setting your map background to 100% washout [Map > Map Layers] you can end up with something like the below.
Now it’s time to add this sheet to our dashboard.
Once you’ve dragged the sheet, which I assume you’ve unpromptedly called ‘Map’, to your dashboard all that’s left to do is add a Set Action, essentially instructing the dashboard to add whichever states are clicked to the IN part of our State Set.
To do this, go to [Dashboard > Actions… > Add Action > Change Set Values…] and configure the options as per the below, paying particular attention to ‘Add values to set’:
You will now see that each state you click will be added to the set.
The Removal List
Our map is all well and good, but once the user has selected a particular state, they’re not able to deselect it; clicking again doesn’t change its status in the set. A slick looking way to get around this is by having a deselection or removal list to accompany the map.
There are many ways you could achieve this, but I like just a simple table that emulates the look of a button list.
Let’s create a new sheet and call it ‘Removal List’. Now drag ‘State Set’ to the Row shelf, this time selecting to ‘Show Members in Set’ and deselecting ‘Show in Header from the dropdown. Next, set the Mark type to ‘Square’ which should leave you with a column of squares.
To get the colour to spread to either side of the sheet, you need a continuous measure on Color. An easy dummy measure to use is simply AVG(1), which coupled with selecting ‘Fit Width’ on the view, will give the desire effect. You can then choose which colour you’d like and, in this case, we have chosen the borders to be white to distinguish between the “buttons”.
Lastly, we need to add the labels by [Ctrl] + dragging ‘State in Set’ from the Rows shelf to ‘Label’. From there, we open up the ‘Label’ mark, select ‘Show mark labels’, centre the alignment and edit the label by clicking the ellipsis. Adding an ‘x’ followed by a space before the state name will make the list’s use that little bit more intuitive, then colour to taste.
Now we need to drag this one to the dashboard next to our map and repeat [Dashboard > Actions… > Add Action > Change Set Values…], configuring as below:
With a bit of formatting you should end up with your dashboard ready for you to select and deselect states at your leisure.
The Finisher
You might have noticed that once you select a state, it washes out other elements of the dashboard unless you click off into whitespace, which doesn’t affect the function but doesn’t necessary look the best:
My fellow DSAU7er, Kevin, found this nice trick to prevent this from happening. In your Map sheet, create a dummy calculation that is simply the word ‘TRUE’ and drag this to the Details on the Marks card:
Jump back to the dashboard and go to [Dashboard > Actions… > Add Action > Highlight…] and configure it as below:
And there you have it! Happy clicking!