问题
I'm using Tableau Desktop 8.0 to create a visualization (.twbx file) by extracting the data from MySQL database. But this database is updated on weekly basis. That is, at the beginning of every week the data in the database changes. So is it possible for me to schedule a task of refreshing the extracted datasource automatically at specific interval of time(i.e. on weekly basis in my case) so that, at beginning of every week the datasource should be refreshed according to the new updates in database and the report should reflect results accordingly. Can this be scheduled through Tableau Desktop automatically? The very fact that it can easily be done on Tableau Server is known to me. But I cannot afford for a Server so trying to get an answer if the same is possible with Tableau Desktop edition.
回答1:
Have exactly the same problem, only I have to update hourly my database :)
The final solution is going for Tableau Server. While I don't have it, I didn't find any "reasonable" solution for the problem. Extract data API can be used (with lots of effort) to update (replace) .tde files, but yet you'll not be able to generate a .twbx automatically (which is probably what you want to do. It's what I need at least).
So I went to a non-elegant solution, used win32 api to make a script to give keyboard commands. Basically I open the .twb file (if not already open), bring it to front, give an alt + d + x command (refresh all extracts), hit enter, wait for some time (in seconds, didn't figure out how to discover if the process is done), hit enter again, alt + f + k (export packaged workbook), some shift+tabs to go to folder prompt, enter the path, a few tabs to get to name prompt, enter the name, enter again, voila
It's not only a non-elegant solution, but a very unstable one too. I run Tableau Desktop on a virtual machine, and my script will only work if I'm actually logged in to the machine (otherwise it will not run the keyboard commands). If you have Tableau on your actual machine, well, you need to make sure there's nothing there to mess with your script when you run it.
Not good solution, but the best I have :(
回答2:
One approach is using Python and the Tableau Data Extract API to update the data extract for a packaged workbook (.twbx). If you're not familiar with Python it's worth looking into, it's a pretty intuitive programming language with powerful libraries for loading in data from csv, excel, MySQL, SQLite, APIs, etc. It's a great a language used in web applications, data analysis, office automation, and so on.
With Tableau Desktop you get access to the Tableau Data Extract API in Python. In addition to the Data Extract API, the sort of trick to this is that packaged workbooks are actually a different type of zip file. So the general steps are: unzip packaged workbook > load in new data > create new data extract w/ API > replace extract > zip back up as a new packaged workbook. Below is a link to a gist with the full code. After creating a python file you could schedule it's execution. But yeah, Server is the best solution for scheduling automatic refreshes, along with some other great features, although I understand it's hard to justify at a small scale.
Link to code!
来源:https://stackoverflow.com/questions/27782900/how-to-refresh-the-extracted-datasource-automatically-in-tableau-desktop-at-spec