Christina Gorga recently commented on Twitter that she would love the ability to copy or duplicate text boxes on Tableau dashboards.
The tweet attracted favourable attention, with 44 likes. One reason the feature is seen as useful is that it could reduce the time taken to copy formatting throughout a dashboard; styling like fonts, sizes, colours, borders. How much of a pain is it to reapply these to multiple text boxes?
The good news is that there is a Tableau feature request (idea) to copy and paste objects in a dashboard, and we can vote for that to try to get it onto the product roadmap! Like any product development team I’m sure Tableau have to prioritise their investment, and up voting ideas gives them an idea of what to focus on.
In the meantime, if you’re willing to take some risks in a non-critical Tableau dashboard, there is already a way to copy and paste text boxes. I’ve seen this idea mentioned on the forums by Andy Cotgreave, and he quite rightly points out that it is likely to be unsupported. So if you’re going to try it, then take a back up of your workbook first. I’ll tell you more about why this is important towards the end of this post! For now trust me and take a backup.
Right let’s work through the how to guide. Please do excuse the awful dashboard design; it’s purely to illustrate the approach.
How to copy and past text boxes in Tableau
Note that this approach is for floating layouts!
Step 1 is to setup an outline dashboard and add your template text box – this is the text box format you want to copy throughout. In this example it’s the text in the top left and I’d like to duplicate the style in the bottom left and bottom right.
Step 2 is to close your workbook and open up the .twb in a text editor (like notepad) instead of Tableau Desktop. The file is mainly metadata about how to transform and display the actual data in your data sources, and is encoded in XML. XML is generally human readable and, importantly to us in this case, human editable. Once open in a text editor find the section that starts “dashboards”. Within this section you should find a section for your particular “dashboard”. I’ve highlighted the section for my dashboard below:
I’ve also added some annotations to draw your attention to two parts. A is a zone of type=”text”. As you can see part way down and to the right, it includes the text that I placed at the top of my dashboard. You can see other layout and formatting elements and attributes in this overall section like x and y coordinates, height and width and some styling. One aspect not included here is text alignment. You can see that in the section of XML I’ve marked B.
Step 3 is to copy that <zone … id=”X” …>…</zone> element of XML (in my case X=1, but your case will likely differ). I’m going to paste that block back in twice (as I want two more text boxes) and I’m going to paste at the bottom of the zones section, just before the </zones> closing tag, as you can see in the next screenshot:
What you’ll see I’ve also done is
- updated the id=”…” for each of the copies I’ve pasted in to be the next highest id number based on the preceding zones.
- updated the x=”…” and y=”…” coordinate values appropriately (I made my life easy here by having a 2×2 grid where I’d already added elements to two spots, so I can just copy the appropriate x and y value from preceding zones, and I didn’t need to edit width and height). Don’t be phased by the x, y, width and height values not looking like the corresponding pixel values in Tableau Desktop. You can always grab your calculator and work out what you need from other values, or just offset enough from other zones that you can subsequently fix it up in Tableau.
- finally I updated the text in the formatted-text > run elements. You don’t have to do this here in the text editor though, as you’ll be able to edit it in Tableau Desktop too.
Cool. Save those changes, close your text editor and …
Step 4: Reopen the workbook in Tableau Desktop. You should see that the pasted text boxes show up with pretty much the same styling:
There is one slight problem though - the text alignment isn’t the same. We can fix this!
Step 5 in this guide is to close Tableau Desktop, reopen the .twb in a text editor and add a bit more XML. Obviously if or when you are doing this for real you’ll do step 5 at the same time as step 3 above. We need to copy and paste the text- and vertical-align format styles too as illustrated here:
You’ll see that I’ve had to derive the relevant id=”dash-text_X” value. The X matches the id chosen for the previously pasted in zones. Save your changes again.
Step 6 is to reopen in Tableau Desktop and you should see correctly aligned text:
There you go. Copy and pasting text boxes in Tableau!
Yeh, but…
I went on to try copy and pasting a non-text box zone. I copied a chart zone and edited the id, and changed the name to another unused chart from my workbook. When I reopened the workbook in Tableau Desktop I got an error. The error told me to contact support. I’m pretty sure Tableau Support don’t want to hear from me after I’ve hacked the underling XML. And I’m pretty sure I know what one of their first questions would be; “do you have a backup you can revert to?”!
I’ve used this approach to copying and pasting text boxes for a couple of Makeover Monday submissions, but not on work projects. Nevertheless I believe I’ve learnt a bit from the underlying XML behind my workbooks, and it makes me think that if the idea referenced above is up voted enough it wouldn’t be a big stretch for the development team to iterate some potentially very well received functionality.
PS. if you want know more about XML, then check out this resource.