Sunday, September 24, 2017

User-Generated Batch Printing in Tableau with JavaScript

I love using Tableau to publish interactive data visuals, but if you publish Tableau visuals in a workplace, sooner or later you're going to get a request for batch-printing.

If you have Tableau server, this can be done using tabcmd, but it requires work by the BI team for each request. It's okay for a few one-off requests, but if you have hundreds of users who want on-demand or customizable batch-printing, it's not a great solution. Instead, we can allow the user to do their own batch printing using JavaScript.

The basic plan is:
  1. Make a URL that generates Tableau dashboard PDFs
  2. Make a dashboard that can be filtered to a list of the URLs
  3. Use the JavaScript API to get the list of URLs
  4. Use JavaScript to batch-download the dashboard PDFs
If you'd like to skip the tutorial, here's a working html file that contains the code and you can skip to the bottom for a demonstration. Even if you read the tutorial, the html file is useful to see all the code in the right order, and the JavaScript libraries used.

Step 1: Make a URL that generates Tableau dashboard PDFs

Tableau will generate a pdf of a dashboard view if you include ".pdf" at the end of the workbook name in the url. Tableau can also receive filter values as url parameters, which will allow the user to customize the view. Andy Kriebel has a nice blog post on url parameters here. Andy's post generates PNG files, but PDF is the same concept.

In my case, I created a one-page of home price data by major US city, using Zillow data. Here's an example using my city:

The url to create this pdf is:

To switch to a pdf of Chicago, and change the time comparison to five years:

Once you have your URL, make a calculated field in Tableau that generates the URL, given the user selection. In my case:

Step 2: Make a dashboard that can be filtered to a list of URLs

Make a worksheet that contains only the URL variable and your filter variables:

"Time Comparison" doesn't appear in my filter list because it's a parameter. Next, make this pretty by putting the worksheet on a small dashboard with filters showing and the URL list hidden.

Step 3: Use the JavaScript API to get the list of URLs

I adapted this code from Tableau's github page on the getData() functions. First, we initialize the visual:
var viz, sheet, table;  
function initViz() {  
     var containerDiv = document.getElementById("vizContainer"),  
          url = "", 
          //replace with your tableau url  
          options = {  
               hideTabs: true,  
               hideToolbar: true,  
               onFirstInteractive: function() {  
                    document.getElementById('getData').disabled = false;  
     viz = new tableau.Viz(containerDiv, url, options);  
Next, we use the getSummaryData() function to get the urls and reshape the data array. This command will be called in our html from a button click (below), after the user has made their selection in the Tableau visual.
function getSummaryData() {  
      sheet = viz.getWorkbook().getActiveSheet().getWorksheets().get("URLs");   
      //replace "URLs" with the name of your worksheet containing the URLs  
      options = {  
           maxRows: 0, // Max rows to return. Use 0 to return all rows  
           ignoreAliases: false,  
           ignoreSelection: true,  
      sheet.getSummaryDataAsync(options).then(function(t) {  
           table = t;  
           var tgt = document.getElementById("dataTarget");                      
           var data = table.getData()  
           var value_array = new Array();  
           //reshape array to fit download code  
           for (var i=0;i<data.length;i++){  
           value_array[i] = new Array (data[i][0].value);  
           //call download function from above  
           downloadAll( value_array )  
Step 4: Use JavaScript to batch-download the dashboard PDFs

The last function in the above code, downloadAll() has not been defined. This function loops through the urls and downloads each pdf. I adapted downloadAll() from this code. Unfortunately this code only works in Chrome; other browsers will just show a single PDF.
function downloadAll(files){  
      if(files.length == 0) return;  
      file = files.pop();  
      var theAnchor = $('<a />')  
           .attr('href', file[0])  
Last, we use html to call our JavaScript functions:
<body onload="initViz();">  
      <div id="vizContainer" style="width:100%; height:300px;"></div>  
   <div class="page-header">  
     <button id="getData" onclick="getSummaryData()" class="btn" disabled>Get Reports</button>  
      <div id="dataTarget"></div>  
Here's the code in action below. The files might take a few seconds to download because the Tableau Public server has to generate each one.

Home Price Profile by City: Batch Printing

A great next step for this project is to get the multiple file download to work in browsers other than Chrome. 

It would also be helpful to rename the PDF after the city instead of the dashboard name. However, JavaScript can't rename an external file, so this would require downloading the PDF to a web server, renaming, and then downloading to the client.

Another next step is to stitch together the pdfs. This also can't be done in JavaScript and would require an intermediate download to a web server.

Let me know in the comments if you use this code, or let me know on twitter.


  1. This plan will be only work if you read the tutorial, the html file is useful to see all the code in the right order, and the JavaScript libraries used.

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training India. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  3. A visual originator should set up the format and illustrations for the first information sheet

  4. This comment has been removed by the author.

  5. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. 55printed

  6. Thanks for the great tutorial, I can't wait to get home and try it out! Perhaps this will make my life with reviews of online proofreading service which is a bit better. Cuz you know it's getting boring.

  7. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
    box file

  8. Often with tee shirt transfers there is a a yellowish hue around the printing. This is caused by the coating on the transfer paper that bonds the ink to the shirt. gifts for companies

  9. I'm impressed, I must say. Very rarely do I come across a blog thats both informative and entertaining, and let me tell you, you ve hit the nail on the head. Your blog is important.. drukowanie 3d

  10. Despite the sort or innovation that is utilized, the most vital thing to search for in a photograph printer is photorealistic quality. Everything else is optional.wydruki 3d

  11. Apple has released iOS 12 beta for developers. You can download latest iOS 12 beta for your iPhone and iPad right now, using our direct links service. Get your device a working iOS 12 beta right now.

  12. It can likewise be fundamentally more affordable for people or little runs on account of the low set cost for ink, paper and expert printing.3d printer reviews guide

  13. This comment has been removed by the author.

  14. nice blog thank for posting such useful information
    broadcast printinghope you will share more post in future.

  15. Some pro printing firms are likewise ready to offer additional wide printing administrations for vast scale outside applications, for example, promoting announcements, hoardings and building wraps.postcards printing

  16. Business card printing can say a thousand words about who you are. A well-designed business card has the capability to attract customers to your business with minimal expenses attached. You can add style by selecting a great layout for your business card and in return, you can expect additional customers. The best part is it's quite easy to design an aesthetically pleasing business card. Leeds Printing

  17. "One of the first producers of exaggerated postcards was William H. Martin, of Ottawa, Kansas. Martin's photography studio began experimenting with trick photography around 1908. His work featured huge ears of corn and peaches, a giant rabbit being tracked by a car, and pumpkins uprooting a farmstead. He was so successful that he established the Martin Post Card Company in 1909, and reportedly produced seven million exaggerated postcards the next year."
    postcards printing

  18. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
    HTML Training in Chennai

  19. It is imperative that we read blog post very carefully. I am already done it and find that this post is really amazing. cheap every door direct mail flyer printing


    this is my tableau public url
    but i'm enable to get pdf links

    i got the error in getSummaryData()

  21. With advanced designing softwares, the art of graphic designing evolved into a new. Since decades t-shirt printers have depended on printing for creating fabulous styles and trends that lived over generations. cheap 3d printer

  22. Video is almost instantly perceived as content. As a result people are more likely to think it's more valuable to pay attention to than simple text is. Letter Printing Direct Mail Service

  23. This is an awesome post. Really very informative and creative contents. This concept is a good way to enhance knowledge. I like it and help me to development very well. Thank you for this brief explanation and very nice information. Well, got good knowledge.
    WordPress website development Chennai

  24. Tableau décoration découvrez le spécialiste de la déco mural Moderne Tendance Contemporain Bouddha Nature Ciné  tableau déco

  25. This comment has been removed by the author.

  26. All the blog writings are demonstration of what we call, Brilliant.
    Sell Copier

  27. This is an awesome post. Really very informative and creative contents. This concept is a good way to enhance knowledge. I like it and help me to development very well. Thank you for this brief explanation and very nice information. Well, got good knowledge.
    WordPress website development Chennai

  28. I’d need to talk with you here. Which is not some thing I usually do! I spend time reading an article that will get people to believe. Also, many thanks for permitting me to comment! JSON Beautifier

  29. Good post but I was wondering if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Appreciate it! T-Shirt Printer

  30. thanks for give us such knowledgeable article Batch Printing

  31. This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
    This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 

    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

  32. I found a good site, the main thing is that here I am not cheating everything honestly
    honest gambling machines I sit play, have fun

  33. Thanks For Sharing your Information The Information Shared Is Very Valuable Please Keep Updating Us Time Just Went On reading the article Data Science Online Training Hadoop Science Online Training AWS Online Training Python Online Training

  34. This is one of the best and valuable blog, I have seen since past some time. Thank you so much for sharing this blog with. Visit Ogen Infosystem for Creative Website Designing Services.
    Website Designing Company in Delhi

  35. Awesome and Valuable information in this blog. Visit Y&H Cargo India for best Logistics and Shipping Company Services.
    Freight Forwarders in Delhi

  36. That was such an awesome content to read and going through it.Thanks for such a good information.our product related for Servo Stabilizer Manufacturer in india and transformer.

    What is Servo Voltage Stabilizer?

    Distribution Transformers Manufacturer in india

    What is Step Down Transformer?

  37. Nice Blog, keep it up for more updates about this type of blog.Carolina Classics is the manufacturer of best F-100 Classic Ford Truck Parts| Buy Ford F100 truck parts online at Carolina Classics.
    Classic Ford Truck Parts

  38. Nice blog, get the best Truck Branding Services in India by Kala Kutir Pvt Ltd.
    Truck Branding Services india

  39. You have to guarantee that you audit your confirmation first, better on the off chance that you have it printed to maintain a strategic distance from blunders that would be printed in a large number of duplicates.Fine art printing

  40. You've made some good points there. I looked on the internet for additional information about the issue and found most people will go along with your views on this website.
    Selenium Training In Marathahalli
    UI Development Training In Marathahalli

  41. When all is said in done there are two kinds of inkjet printers, those with the printhead incorporated with the printer like Epson, Brother and so on and those where the printhead is quite the ink cartridge like HP and Lexmark.cartucce epson margherita compatibili

  42. Visit Djcareerindia for Top 5 DJ Schools and DJ Course in Jalandhar and Top 5 DJ Schools and DJ Course in Visakhapatnam.
    Top 5 DJ Schools and DJ Course in Visakhapatnam (2019 Rankings)

  43. Thanks for sharing this blog
    [url=]best baby photographer in jalandhar[/url]
    [url=]best fashion photographer in Chandigarh[/url]
    [url=]home remedies for hair fall[/url]
    [url=]home remedies to get rid of tanning[/url]
    [url=]Online Digital Marketing Training[/url]

  44. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. Custom Stickers

  45. Identifications : Bags : Bottle openers : Bookmarks : Calculators : Clothing : Diaries הדפסה על מוצרים

  46. I really appreciate your post and you explain each and every point very well. Thanks for sharing this information

  47. Thanks for sharing such a great article and it’s helpful for everyone. Great Post

  48. Printed Limited time Items are generally things or articles which are printed with a particular logo, trademark or notice.הדפסה על מוצרים

  49. Sage customer support team are available to provide the best and effective solution for rectifying the errors. Get the professional tech help from all around the world simply by calling on our Sage Support Number ..

  50. You just dial the QuickBooks Support Phone Number and ask the QuickBooks Experts to install or update your QB on your workstation via a temporary connection. With QuickBooks tech support, you will easily get the solution to all the errors.

  51. i wanted to leave a little comment to support you and wish you a good continuation. wishing you the best of luck for all your blogging efforts.
    Custom Packaging Boxes

  52. thanks for your information really good and very nice web design company in velachery

  53. In fact, this influenced them to think what diverse activities are valuable for those of us who end up all over the place or have confined rigging decisions. sticker printing at home


  54. Hi! Great work. I feel nice to be here reading your authentic work.

    Custom Sticker

  55. This comment has been removed by the author.

  56. This comment has been removed by the author.

  57. awesome blog it's very nice and useful i got many more information it's really nice i like your blog styleweb design company in velachery

  58. This comment has been removed by the author.

  59. These striking some ideas also behaved such as for instance a wonderful way to understand that the remainder have the exact same desires love our possess to see a lot more regarding that problem. I am certain you will find tens and thousands of more fulfilling instances as time goes on for several who have a look at your blog. hp 6968 install

  60. It is ideal time to make a few arrangements for the future and the time has come to be upbeat. I've perused this post and on the off chance that I would I be able to want to recommend you few fascinating things or tips. Maybe you could compose next articles alluding to this article. I need to peruse more things about it! collate printing mac

  61. It should be seen that while asking for papers accessible to be acquired at paper creating organization, you can get unkind perspective. If you feel that the specialist is attempting to cheat you, don't buy inquire about task from it. 24 hours printing shop

  62. Dazzling learning and I get a kick out of the opportunity to give this kind of information to my sidekicks and need they like it they why I do photoshop create vector image


  63. Awesome post. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.

    ACP Panel
    ACP Sheets
    ACP Sheet
    Aluminium Composite Panel
    ACP Sheet Price

  64. The article was up to the point and described the information very effectively. Thanks to blog author for wonderful and informative post.
    Graphic Designing Pakistan

  65. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. הדפסה על כוס זכוכית

  66. Bharat CSP is nothing but a business contributor and technology services provider to different kind of banks. Online Bank CSP Registration, Official Site for apply online CSP. Start Your Business. Mini Bank & Start Earning from 1st Month Low Investment Easy Process..

    Apply CSP
    CSP registration
    CSP provider
    Top CSP Provider in India
    Apply Online For Bank CSP
    Online Money Transfer

  67. Awesome and Valuable information in this blog. Pure Digital covers a wide range of services from hosting, building your first website to Website integrations and backend systems development.

    Website Design Company in New Zealand
    Website Development Company in New Zealand
    Hosting Company New Zealand
    Website Revamp Company in New Zealand
    Web Hosting New Zealand

  68. Book our affordable, quick & on-time best silver service taxi Melbourne with instant booking and enjoy your seamless travel with our Silver Service Cabs Melbourne.

    silver taxi service
    silver service taxi
    silver service cabs
    silver service taxi melbourne
    silver service cab melbourne

  69. A large number of people, particularly the migrant laborers and factory workers do not have a saving account and even not able to open an account due to lack of valid address and ID proof. As a result they face difficulties to save their earnings in a safe place and look out for solution to send money to their families.

    CSP Apply
    CSP Online Application
    Apply for CSP
    Top CSP Provider in India
    Apply Online For Bank CSP
    Online Money Transfer

  70. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. cheap color copies near me

  71. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! silk screen printing machine

  72. ?m impressed, I must say. Really rarely do I encounter a blog that?s both educative and entertaining, and let me tell you, you have hit the nail on the head. Your idea is outstanding; the issue is something that not enough people are speaking intelligently about. I am very happy that I stumbled across this in my search for something relating to this.Get Best Flameproof fabric from in all over the world.