Is there a way to call SaveTool?

HI,
First of all, thanks for Bokeh, it’s epic.

I’ve been struggling to have a Figure widget exported as PNG.
Learned that export_png() requires Selenium and a headless browser installs.
Installing those to an off-line machine is not a breeze. Alone visiting Anaconda site to get them was a horrible experience. Still in process making it work.

The Figure widget has that nice SaveTool, that is able to save the widget without any Seleniums and friends. Question: I wonder, is there a way to call that tool from the code?
I found an example to modify the SaveTool to accept custom filename, so assuming that making it callable through an instance would not be impossible.

Cheers,
Heke

I found an example to modify the SaveTool to accept custom filename, so assuming that making it callable through an instance would not be impossible.

That’s not really related in any way.

The short answer is probably “no”, but really more information is needed. Is this a Bokeh server application? Or standalone (static) HTML output? Does “from the code” mean “from Python code” or “from JavaScript code”?

If you mean you want to do this from just a plain Python script, the answer is definitely no. Something would need to initiate an actual UI event in an actual browser (whether you yourself are doing it, or Selenium is doing it for you). This sort of hassle is one of the trade-offs of having a highly interactive plotting library for browsers. If static images are your main concern, you might be better off looking at Matplotlib for things.

Alone visiting Anaconda site to get them was a horrible experience.

You don’t have to use Anaconda at all. But you need Selenium and a suitable webdriver (and browser) installed somehow. You can do that with one conda install on any platform if you use Anaconda. Otherwise, how to install those things varies wildly by platform AFAIK.

Thanks Bryan for quick response.

OK. That makes sense. Just wondering that if Selenium can do UI event triggering, it could also be done from Bokeh server.

I am using anaconda to streamline and simplify end-users’ installation procedure.

Cheers,
Heke

Well, this is in fact the one case that might be “yes”, but it would not be completely trivial. It would look something like:

  • Python code sets a property value in order to trigger a js_on_change callback in the browser.
  • The CustomJS callback finds a way to call the save method on the plot view

The trouble is that in general, views are not typically user-accessible. I won’t say it’s impossible, but I don’t know how to do it offhand.

Also BTW the save tool behavior is browser-dependent. AFAIK some browsers will always open a save-file dialog that cannot be avoided. This is another reason that using export_png is just a better option.

Yeah, can imagine that it is hard to implement.

Nevertheless, knowing that SaveTool is a dead end saves a lot of my time, many thanks, Bryan.