New Tools for Images: Print, Email

My supervisor has asked if I can add a “print” and an “email” tool to the images I produce in Bokeh. Has anybody ever done this?

I assume here you are referring to standalone HTML content, not a running Bokeh server application? If so, you are limited to what can be done in JavaScript. You can use the CustomAction Bokeh object to add a new toolbar button, or you could use a separate Button outside the plot.

  • printing

    AFAIK the only readily available JS API available is window.print which will print the entire window (after a confirmation dialog)

    Alternatively, you could save a PNG of a single Bokeh plot the same way the built-in SaveTool does, and send the image to some other server or REST API you have set up that can accept the image and print it.

  • emailing

    I think the only option here is the second one above: generate a PNG of a plot canvas then send that data to some other running server or service you have set up that can actually generate and send off the email. Maybe you can send a message directly to some email server directly from JS but I am skeptical.

If this is a Bokeh server app things are perhaps a bit simpler. You can use export_png directly in Python code to generate PNGs (instead of doing it via JS code), and then the Python code can print or email however you would normally print or email from Python code in your environment.

1 Like