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:
- 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)
- 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
- 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
- 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):
Function to zip the folder:
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)
Change the .zip folder to a .twbx (and delete the old .twbx file if it exists):
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...