Create a Carousel menu in Tableau

I recently posted a somewhat silly viz based on the game Elden Ring, and my main aim in creating it was to try out creating an animated ‘Carousel’ type menu:

This menu has elements that scroll as you select them, and will infinitely scroll through the members (in this case there are six items for each piece of armour).

I wanted to walk through how I did this, as I think it can have some fun and interactive applications.

The Theory

So in order to do this, we need to understand a bit about animations, and when they animate and when they don’t, as well as how we can use that to make the above work.

Firstly it is very easy to make things move from left to right, or right to left from a parameter, you can just have a coordinates measure that updates when you change the parameter. This is the basic part of what we are doing:

Gif showing animated marks

Next, it is also pretty easy to fix the Axes at a point meaning you will only see one element at a time which will animate off the screen when you change the parameter.

Gif showing animated marks and fixed axes

In order to get an ‘infinite’ scrolling effect, this is a little bit trickier, as you need to get the marks from the left (or right) side back over to the opposite side without seeing it visually – as by default they would fly back past on the screen like this (You will have noticed this in the previous gifs):

Gif showing animation with one mark overlapping

The way I chose to get around this was by utilizing the fact we have fixed the axes and can only see one element at a time. What is important here, is that once the marks are off the visible screen, it doesn’t matter anymore if they animate. So what we can do is move the mark off the screen via animation on one click, and then ‘null’ out or remove that mark on the next click – this causes it to disappear from the non-visible part of the view. Then we can bring this mark back in on the other side of the view the next click along. See the below gif which is the same data, but the Yellow mark is no longer travelling across the screen as it has been ‘Nulled’ out when off the screen.

Gif showing animation with no overlaps

It is worth noting that you need a minimum of 4 marks to be able to do this (if you are only allowing one to be visible at a time). If you only had 3 marks, you could then just double the number to 6 and duplicate them in order to get this to work.

The Build

So now we have in theory what we need to do, here are the steps to get it working in Tableau, using the simple example I worked through above.

For this example, I will use a small data set containing just 6 items:

Data set used

These will represent the 6 marks I will be scrolling through.

To start with I need a parameter pID, which I can use to flag the ID central to the view:

Parameter set up for pID

I then need to create some co-ordinates calculations so I can plot these marks based on the parameter. Please note that this assumes we will move through the ID values sequentially – and not jump several values at once.

XUpdate formula

XUpdate is our main driving calculation, it will put the ID equal to the pID at the central position of 1.0, and arrange one to the left and one to the right (at 0.0 and 2.0). It also works out if you are at point 1 or point 6 so you can place these correctly. Finally, anything else will get nulled out and essentially be removed from the view. Note I have used decimal values as this will give me more control of fixing axes later.

Y Formula

Y will just be set to 1, as we won’t be changing this value.

Place them on the view as per below, and then you can see how the animation is actually working before fixing axes:

Set up on Tableau worksheet of initial animations

You can see each time I change the parameter, the mark to the right disappears out and the one on the left appears in, while the other two animate over. Once we fix the axis, this will then mean we get a smooth appearance. We fix the X axis at 0.5 and 1.5:

Fixing the Axis

And now changing the parameter gives you this:

GIF showing animation after fixing the axis

Exactly what I am after! This is all the hard work done, now there are a few bits to sort before the user experience is sorted.

We want to provide left and right buttons rather than a drop-down parameter list – this way there is no chance of accidentally skipping any marks and messing the animation up.

This can be done simply using two other worksheets (or one depending on where you put your arrows) and two calculations:

ID_Left calculation

This will allow us to change the parameter using a parameter action when you press a left arrow. It basically takes the current parameter value and reduces it by 1, or sets it to 6 if we are on 1 already. You can add this to a separate worksheet like this, using an arrow shape:

Left arrow setup

Then add this to your dashboard, along with the following parameter action:

Parameter action setup

This will achieve the following:

Gif showing left button working

And you can rinse and repeat for the right arrow with a slightly different calculation:

ID_Right setup

Add it to the dashboard with another parameter action, and we have it working!

Gif showing right and left buttons working

One more thing is to use the TRUE/FALSE filter trick to deselect the arrows as soon as they are pressed, to improve the user experience. Then tidy up the formatting and we are done!

Gif showing final carousel animation working

I hope you found this interesting! I have posted the workbook to Tableau Public if you want to have a look yourself:

Animated Continuous Carousel Example

Thanks!

Ant.

One thought on “Create a Carousel menu in Tableau

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s