Online tableau training, tableau tips, & video tutorials
How to Show Selections with Button Swapping in TableauPreview
Dynamically change images in a navigation to highlight choices
Ryan shares an innovative technique for highlighting dashboard selections in Tableau. You’ll see how to set up images as a navigation and/or filters; then how to change the background color on an image that has been clicked.
Hi. This is Ryan with Playfair Data TV and in this video, I’m going to show you an innovative technique that shows you what selections have been made on a Tableau dashboard. I’m calling this technique, button swapping. There’s a video here at Playfair Data TV that shows you how to do sheet swapping in Tableau. That’s a popular technique that’s been around for a while, but this one’s different in that it allows you to swap out individual images that are being used as filters or navigation to show you what has been selected.
Let me show you what I’m talking about over here in Tableau Public on my visualization called BLOCKBUSTER. This looks at the 10 highest grossing actors of all time. And as you can see, each actor that made the top 10 has a little avatar image. Notice that the actor that has been selected, has a red background, where everybody else has a gray background.
If I go into presentation mode, and if I click on the second ranked actor, which is Harrison Ford, you’ll see that his image now gets a red background. So this is more than just a highlight effect. It’s literally swapping out the image in the background, which is a nice user experience. It’s a very web-like experience, and it’s made possible only because of the new set actions that are available as of Tableau 2018.3.
So let’s take a look at how to do this. The first thing you’ll need to do is setup two sets of images. So here’s how this looks. These are my complete sets. I’m just going to show you a sample of the first five actors. Notice that I’ve got an avatar for each actor in both their selected state, as well as their unselected state. You would then need to take these images and put them in a folder that lives in your Documents project, and it’s called, My Tableau Repository. When you installed Tableau, it automatically installed this folder for you and it’s a repository for files that are related to your installation of Tableau Desktop.
One of the folders within your Tableau Repository is called, Shapes. And within that Shapes project, you can make new folders to put in custom shapes. Any shape that you put into these Shapes folders will be available to you as a Shapes palette, if you’re using a mark type of Shape for a chart over in Tableau Desktop. This will make a lot more sense once I show it to you, but this is just the setup.
So setup your images. You need two different sets. One’s the unselected state, the other is the selected state. Then, navigate to this folder, create a new custom folder for your new shapes, this will then be available to us later on when we go to create our navigation.
Over in Tableau Desktop now, I will make that control sheet just by starting with Actor on the Text Marks Card. Just so you can see the five actors that we will be mapping in this example. Next, I’m going to change the mark type from Automatic, which is currently set to Text, to Shape. And move that pill from the Text Marks Card to the Shape Marks Card.
So now each of my five actors has an individual shape assigned to them. The next thing we need to do is create a set from our Actor dimension, or whatever dimension you are using as your navigation. To create a set, I’m going to right-click on the dimension, hover over Create and click Set. I will call this my Actor Set. And whatever I choose here will put that dimension member into the set.
Well, in order to get button swapping to work, we need to map both the complete unselected state, as well as the complete selected state. So for now, I’m going to leave everything unselected and click OK. And you see we’ve got a set down here, Actor Set. Now here’s the kind of hacky part, where we’re going to fake Tableau out, in order to use this technique.
We’re going to set up a calculated field that concatenates the dimension that I am using for my navigation with my set. This will allow us to map whether they are selected or unselected because it will add a t or an f. So true or false before the name of the actor. And if we do this right when we’re setting this up, only one of the actors will have a t preceding their name, so they will get that selected state treatment when we go to map the images to the dimension members.
The calculated field is very simple. I’m going to right-click on my dimension and setup a calculated field, and I’ll call this my Selected Actor. And the formula is the name of my set. Actor Set plus Actor. But there’s one little thing that’s throwing this off, and it’s because we’ve got different data types, it’s what it’s going to tell us here.
The Actor Set is Boolean. You’re either in the set or you’re out of the set, so it results in two outcomes, true or false. The Actor then is a dimension that is qualitative and it has a data type of string, so what Tableau is telling us is we can’t combine Booleans with strings. Very simple fix, just need to precede that Actor Set with the function STR, which converts that to a data type of string.
Now the calculation is valid. I’ll go ahead and click, OK. And instead of mapping the Actor dimension, what we actually need to map, are these Selected Actor dimension now. So I’m going to replace this pill Actor on the Shape Marks Card with this dimension, Selected Actor. And you can do that by just dragging it and dropping it right on top of what was there.
You don’t see the shapes change, but notice over here on the left, the names of the dimension members change. Every single dimension member is preceded by a lower case f. If we look back at our set, that is because we have no actor selected, so the outcome for all of them is false. Currently, nobody’s in the set. So this is our unselected state.
I’m now ready to go ahead and map these dimension members to those specific shapes that I put in my Tableau Repository. To do so, there’s a couple ways to get to it. You can click the Shape Marks Card, or just double-click on the Shape legend over here, which will open up a place where you can map shapes to individual dimension members.
If you click this dropdown, you will see all the different palettes that you have available to you to choose images from. This is why we put those images in that custom folder. Once I put those there, we now have a custom palette called, Button Swapping Example. If you don’t see your custom palette, it’s probably because you’re doing this for the first time. Simply close that dropdown for a moment, and click Reload Shapes. That will then go refresh those custom shape palettes and it should be available to you.
I’m going to click my Button Swapping Example, and from here, I’m going to map the unselected state for my top five actors here. So Antony Daniels is this– and make sure I’m choosing the unselected images. So Morgan Freeman, I’ll choose the one with the gray background, Sam Jackson, gray background, Scarlett Johansson, gray background, and Tom Cruise, gray background. Click OK.
Make these a little bit bigger so we can see them. Actually, to make that easier, I’m going to throw Actor on the Columns Shelf. This gives me a little more flexibility in how I resize these. Click on the Size Marks Card, make that a little bit bigger. We’ll call that good for now. I don’t necessarily need the headers, so I’ll go ahead and hide those. Don’t necessarily need the lines, so you can obviously clean this up as you would like. We’ll call that good.
Now, I’m ready to map my selected state. So my unselected is in a good spot. To put a t before each of the dimension members, I need to make sure all five actors are in this Actors Set. So I’m going to go back here and edit that set, and I’ll choose All this time, and click OK. And notice, the shapes that we had mapped, got cleared out. It’s because we had mapped all the dimensions members that had an f preceding them. They now have a t preceding them, so Tableau is interpreting these as different dimension members.
This would be dimension members six through 10, where as we mapped dimension numbers one through five. So this is the selected state. I’m ready to go ahead and map these now to their respective images with a red background. Sam Jackson, Scarlett Johansson, and Tom Cruise. So we now have everything mapped, both in a selected and an unselected state.
I’m temporarily going to clear out that Actor Set again, just to show you that we still have the unselected state intact. And now we’re going to use set actions to tell Tableau which actor has been selected. So over here on a new dashboard, I’m going to just use this one sheet, obviously, you can use your imagination. I showed you the final result over on Tableau Public, but once you have this in place, you can use this to link it to other sheets, obviously. I’m just going to show you this sheet alone for the example.
So we’ve got one sheet. I’m going to add a dashboard action by navigating to Dashboard in the top navigation, and then click on Actions. Click, Add Action. This is a Change Set Values action, so I click on that. And we’ve only got the one sheet on here, and this is my only dashboard action. The important thing is this area right here, the Target Set. So it’s the BLOCKBUSTER data source, and we are targeting this Actor Set.
I’m going to click on that. There’s a couple of other options here, such as, when do you want that action to execute? I like the default here, which is Select. That’s synonymous with click. And then you also get to decide what will happen if you clear out the selection. For this specific tactic with button swapping, I would probably go with Keep Set Values. What that will do is keep your last selection in place until another selection is made. Whereas, the default, Add All Values to Set, will make them all look like they have been selected.
So for this tactic I’m going to choose Keep Set Values. We’ll call that good. I’ll click OK, and click OK again. And now, when I click on an actor, we should see it turn red. And we should be able to do this one at a time. Technically, because these are sets, you can even do a multi-select. So if I hold Control, and click two actors, both of them will be added to the set, if you would like to do that.
If I clear out the selection by clicking the Escape key, because we set up that set action to say, keep the last selection in place, then we still have those two selected. It will stay like that until I choose a different one. But what’s happening in all of these cases as I click through this list, is it’s replacing which actors or dimension members, specifically. I keep saying actors because that is the exact use case that I’m using, but this will work with any dimension and any dimension members.
What it’s doing is when you click on a dimension member, it’s overriding that value in the set and because we mapped different images to the selected dimension member versus the unselected dimension member, it’s highlighting it and giving it that appearance, or improving that user experience, to show you what has been selected.
This has been Ryan with Playfair Data TV – thanks for watching!
Related video: 3 Ways to Smooth the Excel Transition
Related video: An Introduction to Tableau Dashboard Actions
Related video: Two Ways to Dynamically Display the Top N vs. Other
Related blog post: How to do “Button Swapping” in Tableau
Related visualization: BLOCKBUSTER
- An Introduction to Tableau Level of Detail Expressions
- How to Use LOD Expressions to Create Benchmarks
- Exercise: Use LODs to Compare Sales to a Benchmark
- How to Use a Tableau Set Control for Scenario Planning
- How to Make a Custom Polygon Map in Tableau
- How to Make a Tableau Toggle with More Than Two Choices
- How to Make an Integrated Toggle Switch in Tableau
- How to Normalize Current Dates and Prior Dates on One Axis in Tableau
- How to Isolate Comparison Date Ranges in Tableau
- Using Tableau’s Parameter Actions Extension to Change Date Parts
- How to Use Parameter Actions to Change Date Parts in Tableau
- How to Dynamically Change Date Parts in Tableau
- Two Ways to Dynamically Display the Top N vs Other in Tableau
- How to Pass Filters and/or Parameters Between Tableau Workbooks
- How to Automatically Highlight Highs and Lows in Tableau
- How to Map a Custom Background Image in Tableau
- How to Compare the Last Two Full Date Parts in Tableau
- How to Compare the Last Two Partial Date Parts in Tableau
- How to Show Selections with Button Swapping in Tableau
- How to Use Tableau Sets to Create Relative Date Filters
- How to Change Sort Order Across Multiple Sheets in Tableau
- How to Scroll Multiple Sheets at Once in Tableau
- How to Turn Normalization On and Off in Tableau