Download 'All Results' from a dashboard

  • 3 April 2021
  • 0 replies
  • 450 views

Userlevel 3

Currently, the ability to download unlimited results from a dashboard is not directly possible - the UI does not surface an option to do so, and attempting to do so via scheduler endpoints in the API will yield you validator errors (for example). 

That said, like most limitations, this can be worked around with a bit of elbow grease, the Python SDK, and a few for loops. High level, we can use the `search_dashboard_elements` and `run_inline_query` methods to get the query object generated by each tile, remove the row limit, run a new query without row limit, and finally download the results of each query. I wrote a script that illustrates this, see full code here: 

https://github.com/NestleJsCrunch/LookerScripts/blob/main/DownloadDashboardUnlimited_colab.ipynb

Walking through the key parts:

data = sdk.search_dashboard_elements(dashboard_id=dash_id)

Here we’re getting a dictionary with the json for each element on the dashboard.

for x in range(numelemnets):
element_query_body = data[x].result_maker.query
element_query_body['limit'] = -1

We’re then looping through each list, grabbing the `result_maker.query` object and changing the `limit` parameter to `-1` (aka all results). 

      elements_needed = ['model','view','fields','filters','sorts','limit','query_timezone']
final_body = {}

for y in range(listlen):
try:
new_el = element_query_body[elements_needed[y]]
except:
i+=1
else:
final_body[elements_needed[y]] = new_el

Since we only need a subset of the elements in the `result_maker.query` object to run a new query, we are initializing a list with just the keys for those elements. Then we then use another nested loop with a try catch statement to create the final body that we can pass into a call to `run_inline_query`. The try catch is necessary because not all dashboard elements will have `filters`. 

      resultset = sdk.run_inline_query('csv', final_body)

Finally, we run the new query with the body that we created in steps above and can download that result set via whatever methodology we prefer. This should all happen in one loop for a given tile, then can repeat for the next tile.


0 replies

Be the first to reply!

Reply