0

I have read through this question: What's the command to "reset" a bokeh plot?

Which is close to what I'm trying to do. Except I'm trying to use an HTML button and have the JavaScript reset the bokeh plot, rather than creating a button in Python and tying the JS Callback to that python button. How can I pass the reference of the bokeh plot up to the javascript?

Russell
  • 3,384
  • 4
  • 31
  • 45

2 Answers2

0

Bokeh populates a global Bokeh.index structure with all the views that are renderered on a page, and an Bokeh.documents structure with all the documents on a page. You will need to sift through one of those to find the Bokeh model that you are looking for. Typically setting name on the Python side will make this easier, so that you can search for the object with that name value.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
0

If you have plot with a glyph in Python like this:

p = figure()
renderer = p.line(x=[1,2], y=[1,2], name='lines')

Then you can access the renderer model in JavaScript as follows:

renderer = Bokeh.documents[0].get_model_by_name('lines')

You can do it in Bokeh callbacks as well as in any 3rd party JS libraries you are using in your Bokeh app.

However, if you want just to reset the plot using the ResetTool you could do so in JS just by clicking on the ResetTool icon in the toolbar and without referencing to plot model like this:

reset_btn = document.getElementsByClassName('bk-tool-icon-reset')
reset_btn[0].click()

The above works for Bokeh v1.3.0 and is not guaranteed to work in the future versions as Bokeh CSS library can change.

Tony
  • 7,767
  • 2
  • 22
  • 51