Get plot png screenshot without selenium dependencies

By default bokeh plots offer a direct png export without any additional dependencies.
However for the export_png or get_screenshot_as_png function a selenium + ChromeDriver dependency is required.

I am wondering if that can be avoided because the JS code for the direct png export is basically already available. In other words I’d like to use the get_screenshot_as_png functionality without the additional depencencies.

The “on-plot” save tool has immediate access to the HTML canvas and can just save the data out from JavaScript. Anything from Python will have to drive a browser to first generate a plot to save, full stop. In the future, it may be possible to avoid Selenium, e.g. by using the Chrome dev APIs directly, but a browser of some kind will always be a requirement. If you need to generate images without a browser, then you should probably look to other tools.

I probably wasn’t really precise what I actually need. The browser is still available in my case and I’d like to transfer the png image back to Python from the JS part for further processing (embedding png images into pdf/powerpoints, etc.).

Oh I see. That should be technically possible, but there are no APIs built-in to Bokeh to make it happen. An very rough toutline of what you might do:

  • Use a CustomJS callback to locate the canvas DOM element and call toBlob to get its data
  • Use a CDS (or DataModel) as a dd to synchronize canvas binary data back to Python

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.