Export Bokeh dashboard in one file

I have developed a dashboard in Bokeh that is running as a server (in Dataiku environment). Now, I need to export the page (actually a rearranged selection of the charts and tables) as a PDF, but an HTML file would be also good.

I expect to have a button “Generate report!”. Upon click I will get a dialog offering the download of the PDF/HTML report.

The first problem is - how can I generate the file on the fly and serve it via the dialog without saving the file on the server first? Or do I have to save it first?

Bokeh has no capabilities regarding PDF export. There are APIs to generate HTML output, but only from Python, which implies a Bokeh server application. Are you running a Bokeh server application? If not, I am not sure there’s much beyond trying something like described here:

e.g. from a CutomJS callback that you attach to a “Save” button.

Yes, I am running a Bokeh server application. I was searching for a way how to achieve this in python, but without success so far. I know I can save the html file on the server and then download it. I would rather serve the file without saving.

There is not any straightforward way. If you generate HTML output in the server, you could potentially communicate it back to the client in some property (e.g. a text property for a hidden div, or better, a property on a new DataModel subclass) and then potentially a JS callback on the property could extract the HTML string and offer to save it. But I’ve never actually tried, so I don’t have anything ready at hand to point to, you would just need to experiment.