Continuing with Tableau Server automation, in this section, I shall demonstrate how to build a a method to print your dashboard to pdf and then send to a group of recipients. The following assumptions have been made:
|
You can print to png using the same command, both outputs shall be scalable. Usage is generally:
|
Tableau server already has a print to pdf/png and email function, however, users can often find this quite limiting in what options can be selected; furthermore, users are limited to a simple 'vanilla' output with no control offered as to exactly what to send.
Timings are also a consideration as well, with Tableau server, just like refreshes, these are rigidly set; Tableau has a basic configuration that users can define whether a report is sent, so if the workbook is in the process of refreshing, the report can be configured to not be sent, but unless you set another print for later, no report shall be sent that day; but if everything is ok, then a report shall be sent each time - also not great.
This method is just as easily attached to a complete etl refresh; this is actually covered in more detail on the full build here :Part 4: A Data and workbook refresh: complete build (20 minute read) - On a Tableau Quest... - Confluence (atlassian.net). Though for this page, I'll be just looking at the print to pdf and send though with a slight twist, as here we'll use some parameters to control the dashboard before printing. These controls are just as easily added to any build.
Lets build a dashboard, using Superstore Sales, something simple then:
Now save the workbook as a packaged workbook call it Superstore.twbx and upload your workbook to your server, and take a note of workbook and sheet name as given by the server on upload, mine is "superstore/Dashboard1".
As with everything in tabcmd, here, we shall create a script to instruct tabcmd on what to build.
Depending on how far you want / need to go, you can get quite creative here; some previous examples of my work include using sql on the data side to determine whether a data-quality report needs to be sent; or in the case of an A/B or MVT test dashboard, using sql to determine which experiments have ran their course, and are ready to be examined, grabbing the experiment codes and version numbers, then building on the fly a script to be executed in just a moments time. |
For our script, we shall be pulling down two pages, one at the highest grain, the second filtered to South, both as png ready for sending:
cd c:\tabcmd\tabcmd tabcmd login -s <your server> -u <your username> -p <your password> tabcmd export "superstore/Dashboard1" --png -f "C:\tabcmd\prints\superstore_high.png" tabcmd export "superstore/Dashboard1?p_Region=Central" --png -f "C:\tabcmd\prints\superstore_central.png" tabcmd logoff |
The complete script shall login to the server using your credentials, create a high-level png and then a second png filtered to the Central region, saving both to the prints folder ready for sending, before then logging-off. Unless you intend on running more commands in the same script - these scripts can be as long as you need; but it is important to kill your session once you have finished, even if you shall be executing more commands from another script in just a moment.
Now save the script as superstore_daily.bat in your tabcmd scripts folder
I shall be using part of the demo from Part 4 here:
Open SQL Server Integration Services in MS Visual Studio, create a new project, give it a name and press OK to begin the build, this is covered here: Programmatic Workbook Refresh (10 Minute Read) - On a Tableau Quest... - Confluence (atlassian.net) in Step 2
Now we have created the print-to-pdf/png and the email out, the final step is to deploy. Again, I use SQL Server for this; if you don't have access to the server, the Developer Edition is free both for personal and commercial use, but is severely throttled on performance: not too great for database servicing, but more than enough power for etl work like this.
The following steps can also be found from Step 2 of Part 2: A Programmatic Workbook Refresh (10 Minute Read) - On a Tableau Quest... - Confluence (atlassian.net)
First select Build to build the project config, this can take some time depending on the project size, but for this project, the build should be immediate with information included in the Output window:
Build complete -- 0 errors, 0 warnings ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== |
Over to SQL Server Management Studio, refreshing the Integration Services Catalogs will show you your newly deployed project; you won't need to do anything more here but if you were using sql parameters (not the same as Tableau parameters), this is where you can set them up.
Expanding the SQL Server Agent, this is where we shall create the job(s):
The Advanced page of the New Step dialogue box provides more configuration surrounding how to handle timeouts, but also what to do next; as this is a single-step demo, we can avoid this page. Press OK to add the step
Now that you've created your job, it shall run to your defined schedule, which can be easily modified at any time, but, you can also manually initiate the job simply by right mouse selecting the job from the Jobs directory, before then selecting Start Job at Step... |