2 Replies Latest reply on Apr 26, 2016 10:27 PM by Morgan DUARTE

    Auto-refresh Tableau Reader Dashboards (.twbx)

    Lance Dacey

      I spent a few days trying to figure this out so I thought that I would share.

       

      • I have 8 dashboards which I am refreshing connected to two separate data sources.
      • I have fully automated the data download, modification, and consolidation tasks with Python and Windows Task Scheduler.
      • The only manual task that I had to do every day was open each dashboard and refresh Tableau Extract (they are connected to a large .csv file)

       

      My solution was to:

      1. Use the Python API to write a .tde file (by the way, if anyone could create a to_tde method in the pandas library I would be so grateful)
      2. I use the shutil library to copy this file (/tde_folder/dashboard.tde) to a dummy folder with the .twb and a /Data/Data.twb Files/ folder. The new .tde file goes inside the Data.twb FIles folder which is where the .twbx looks for the data
      3. Use a function and os.walk and ZipFile to zip this dummy folder (which contains the .twb and the new tde.). Credit goes to this post: http://stackoverflow.com/questions/10480440/zip-folder-with-subfolder-in-python
      4. Rename the .zip folder to a .twbx folder so Tableau will open it properly

       

       

      Copy the new .tde with the latest data to the dummy location which mirrors the .twbx format (you can open a .twbx with 7zip and check it out):

      shutil.copy2(extract_file, tde_location)

       

      Function to zip the folder:

      os.chdir('C:/Users/OneDrive//tableau_dashboards/')

      def zipfolder(foldername, target_dir):           

          zipobj = zipfile.ZipFile(foldername + '.zip', 'w', zipfile.ZIP_DEFLATED)

          rootlen = len(target_dir) + 1

          for base, dirs, files in os.walk(target_dir):

              for file in files:

                  fn = os.path.join(base, file)

                  zipobj.write(fn, fn[rootlen:])

       

       

      zipfolder('zippedfile', 'thefolderyouarezipping')

      exit

       

      Change the .zip folder to a .twbx (and delete the old .twbx file if it exists):

       

      if os.path.isfile('dashboard.twbx'):

          os.remove('dashboard.twbx')

      for filename in glob.iglob(os.path.join(dashboard_location, 'dashboard.zip')):

          os.rename(filename, filename[:-3] + 'twbx')

       

      Finally, I simply use shutil to copy the files to a shared folder and then email a notification to everyone using the wincom32 library and Outlook. 100% automated now. I am pretty pleased. Obviously, I would prefer to have Tableau Server but I am operating with just one license of Tableau Desktop Professional right now...