Closed johnnychen94 closed 2 years ago
It's non-trivial, since Bokeh only targets JavaScript. The way the Python package does it is to use Selenium to render a web page containing the plot, then taking a screenshot. I'm not sure if there are Selenium bindings for Julia.
It also has the save
button which probably runs a JS
code.
Is there a way to invoke this JS
code from Julia?
It will also be great to be able to export the SVG
programmatically without changing the backend itself.
It's a nice idea, but currently there is no communication back to the Julia process. That will be a complicated extra layer in itself and will probably be a separate package.
What about the SVG idea? Or is it the same issue?
Don't you need only one way communication to invoke the JS code?
If you want to save an image from the browser, either the image needs to be sent back to Julia so Julia can save it, or you need to get the browser to save it. The first option requires communication back to Julia. For the second option, there is no JavaScript you can write which will save a file to disk without the user's intervention - the best you can do is have it bring up a save file dialog, in which case the user may as well click the save button themselves.
I don't think the file format (svg or png) makes any difference.
Let me try explain.
I don't want to save an image from the browser UI.
I want to run something like png(p, "fileName");
or svg(p, "fileName");
and save it to HD.
I don't need any interactivity, just pure Julia code which invokes the relevant Bokeh's JS code.
@RoyiAvital I believe what Christopher says is that Bokeh itself doesn't contain the "save as png" feature -- it dispatches the task to a real browser or browser simulator (e.g., Selenium)
Yes precisely.
I am well aware of that. You mentioned this above and I have read the Python
documentation about exporting.
I am talking about a different path (Might not be feasible). I am talking about pure JS
for exporting which is invoked by Julia
.
In Bokeh.jl
there is a button to Save Image
. It makes the browser download a PNG file.
What I mean is to invoke this code from Julia
in a Blink
window or something. And doing it behind the scenes.
Another thought I had was about the SVG
option.
Run behind the scene the Bokeh.jl
engine to create the xml
structure and then save it without ever presenting it.
This might require some changes in their JS
code, but could it be easy?
Blink is really just a minimal web browser so the above comments still apply. On the other hand it has 2-way communication with Julia built in so taking a screenshot and saving it as PNG should be doable. A Blink backend for Bokeh would be nice to have anyway. Good shout.
@cjdoris , But if you invoke the code beyond the Save PNG
of the plot it will generate a png
file without taking a screen shot. Namely the JS
code can do with directly once it has a browser engine available.
FYI I recently registered a backend using Blink, which also has a (highly experimental) save
function so you can export PNGs of your plots. It's documented here: https://cjdoris.github.io/Bokeh.jl/stable/misc/#Blink.
Good to close?
Is there a way to export a plot to PNG/SVG and save it?
Something like this, I believe, https://docs.bokeh.org/en/latest/docs/user_guide/export.html#example-usage