Exporting a visualization programmatically?

I’ve looked around the forum but the most recent post I found about this topic was from 2018.

I’m looking for a way to export query visualizations programmatically, hopefully without having to use tools such as selenium.

In case you’re wondering why I need this:
my company has several clients and they all want a goddamn monthly report. The CTO still doesn’t feel like making our Redash public to them, so I’d have to manually do this, which is just copypasting job and it’s dumb.

So I’m trying to build something like:

  • a script that, each month, queries my dashboard with the needed parameters (client, date range)
  • export the visualizations and embed them in an HTML template (using jinja2 maybe)
  • save the HTML page as pdf and save it on an S3 bucket.

I would build this using AWS lambda functions, but if you have better ideas on how to obtain the above, please do share!

Edit: for the record, I’m using python so ideally I’d be working with that. Internally we also use JS but I don’t really wanna bother the frontend dev with this, he’s got enough to do already :smiley:

I think Selenium or similar is the only option. Redash doesn’t export PDF’s. The API doesn’t export images.

:laughing: If I didn’t laugh, I’d cry. We’ve all been there! In this case, however, Redash was never the right tool for this job. It’s not a report studio or email system.

Selenium has a Python binding which should be straightforward. Just point your instance at the correct URL and then make a full-page screenshot. Then embed the image in a PDF. You can even chop off the top 50px so the menu doesn’t appear.

Hey @k4s1m, thanks for the quick reply!

Redash was never the right tool for this job. It’s not a report studio or email system.

I knowwww, ideally I would be sharing with each client their own private dashboard but the CTO is not sure yet about this. Tbh I love redash and what it allows me to do, it’s so simple and satisfies all my data reporting needs, without all the fancy pancy stuff of tableau and the like.

Just point your instance at the correct URL and then make a full-page screenshot.

Regarding this last point, so in theory I should be able to:

  • Make an API call to the dashboard with the required parameters (which customer and required date range)
  • Use selenium to open that specific call in a headless browser
  • Wait till the widgets finish loading
  • Save the whole thing somewhere.

Since I’d be using selenium or anything similar, I think I can fetch the HTML of the page and use any of the available solution to convert that to a PDF, no?

Exactly. With one minor adjustment:

This isn’t an API call. It’s just a normal “browser visit” to the dashboard page. You won’t need the Redash API for any part of it :slight_smile:

Uhmm, I thought that having to add parameters to the url (like: my_dashboard.com/?key=blablabla%retailer=ret_1&date_start=2020-01-01) etc would make that an API call.

I guess I’m still confused wtf an API actually is