Importing and Exporting Snowsight Dashboards and Worksheets
Overview
Snowflake’s new web-based IDE announced at Summit 2021 is called Snowsight. It is chock-full of wonderful features like code IntelliSense and auto-complete, object search, ad-hoc visualizations, any size data extract, worksheet and dashboard sharing, and rapid dashboard building.
This article demonstrates how to build dashboards in Snowsight and then clone, import, and export those dashboards (using the community sfsnowsightextensions CLI tool) to share with users across different Snowflake accounts and regions.
If you are not yet familiar with Snowsight, check out the introduction here:
Charts in Snowsight
Snowsight charts offer lightweight and fast visualization of data results. Although not yet comparable in richness to the types of visualizations users can make in Tableau, PowerBI, Qlik, or Sisense, they nevertheless do a great job when you need rapid insights into the query you are working on.
Here is an example. Just a minute ago, I was helping customers understand warehouse resize events from WAREHOUSE_EVENTS_HISTORY view in last week. It looked great as a table, but it worked even better a clustered bar timeline showing me a warehouse in YELLOW that was manipulated quite often to change its size and scaling policy:
And without leaving to go anywhere or any refreshes, just a few clicks changed the chart above to the one below, which provides a per-week summary of the warehouse size changes. It looks like most warehouses in the week of 08/23 wanted to be LARGE:
Dashboards in Snowsight
Once you have a query and a chart that goes with it, it is straightforward to assemble as many of them as needed into a Snowsight dashboard, which is a grid canvas with single or multiple widgets per row and several preset row heights:
Once the dashboard renders, the results are saved in long-term storage, so anyone who opens the dashboard sees something very quickly.
Dashboards could be shared with anyone in your organization, in either read-only mode or allowing target users to modify it.
Exporting and Importing Dashboards and Worksheets
Consider these scenarios:
Sometimes you may want to have many dashboards with similar underlying design but targeting either a different dataset (a table, schema, or a date range), or maybe have the same queries with a variable like customer name or warehouse location substituted.
Or let's say you are a Data Provider in Snowflake Data Marketplace with an interesting dataset. You would like to share not only the data but also a dashboard designed to showcase the dataset.
Finally, some of our customers like to prepopulate user’s workspaces with worksheets containing common queries and dashboards specific to the user’s role.
Those things call for export/import feature for dashboards and worksheets!
Although Snowsight does not have a native export/import/clone functionality (yet), this can now be accomplished programmatically by using Snowsight Extensions!
Exporting Dashboards with Snowsight Extensions
Snowsight Extensions are a collection of cross-platform PowerShell cmdlets that enable Create/Read/Update/Delete operations for worksheets and Create/Read/Delete for dashboards across any account. Snowsight Extensions are used from command-line or script.
First, you need to authenticate using either username/password or browser SSO:
PS > $appContext = Connect-SFApp -Account myaccount
UserName: myusername
Password: ************
Using SSO:
PS > $appContext = Connect-SFApp -Account myaccount -UserName myusername -SSO
Once you have the authentication token, you are ready to do things like retrieving all Dashboards:
PS > $dashboards = Get-SFDashboards -AuthContext $appContext
Retrieved 16 dashboards
Execution took 00:00:03.3065618 (3306 ms)
PS > $dashboards
DashboardID DashboardName AccountName OwnerUserName ModifiedUtc NumRows NumWidgets
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
RVmG8gIh Dashboard 1 aws_cas1 DODIEVICH 4/28/2021 10:28:20 PM 2 4
MMc0Mvsy Dashboard 1 aws_cas1 DODIEVICH 4/28/2021 6:51:24 PM 3 5
8WOgHrkO Dashboard 2 aws_cas1 DODIEVICH 4/28/2021 10:30:01 PM 2 2
OHuc0vF Dashboard 2 aws_cas1 DODIEVICH 4/22/2021 10:53:39 PM 2 3
…
Dashboards are easy to modify straight in console or in a script. Alternatively, they can be saved for additional manipulation as files:
PS > $dashboards | foreach {$_.SaveToFolder(“path/to/folder”)}
PS > $dashboards[0].SaveToFile(“path/to/folder/mydashboard.json”)
The saved data includes dashboard name and execution context, worksheets with their queries, chart configuration, and grid layout structure:
It is easy to edit the SQL query for each of the worksheets, the arrangement of the dashboard in the grid, and the execution context (warehouse, role, database, schema) for each of the worksheets.
Importing Dashboards with Snowsight Extensions
Once you have the dashboard in the local variable or a file with your desired changes, you are ready to import it into any environment of your choice:
PS > New-SFDashboard -AuthContext $appContext -DashboardFile ‘path/to/folder/mydashboard.json’ -ActionIfExists CreateNew
Existing Dashboard ‘DashWithCharts’ will be ignored and new Dashboard will be created because ActionIfExists is ‘CreateNew’
Creating new Worksheet for Chart Worksheet 1 (4ov1hsZ92Jl)
Created new Worksheet Chart Worksheet 1 (5Nva2QcIOiL)
Creating new Chart /chart (1166750) in Chart Worksheet 1 (5Nva2QcIOiL)
…
Inserting table into cell (0, 0) from worksheet Worksheet Chart Worksheet 1 (5Nva2QcIOiL)
Inserting chart into cell (0, 1) from worksheet Worksheet Chart Worksheet 1 (5Nva2QcIOiL)
…
Running new Worksheet Chart Worksheet 1 (5Nva2QcIOiL)
…
Returning Dashboard ‘DashWithCharts (V2HOYw2s)’
DashboardID DashboardName AccountName OwnerUserName ModifiedUtc NumRows NumWidgets
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
V2HOYw2s DashWithCharts aws_cas1 DODIEVICH 5/18/2021 10:13:10 PM 4 8
Execution took 00:00:16.4291362 (16429 ms)
And the imported version of the original dashboard is ready in seconds:
Customer Example
One of my recent customers wanted to provide a pre-built dashboard for their data share that they give out to consumers.
They ran Snowsight Extensions on a Linux desktop to export the dashboard from the original Template, modified its parameters to match the target environment’s virtual warehouse name, and imported the dashboard:
Results just a few seconds later looked great:
Next Steps
If this was interesting, head on over to the Snowsight Extensions home in Snowflake Labs https://github.com/Snowflake-Labs/sfsnowsightextensions and give it a try!