Trigger callback when a selection is cleared?

Hello,

I have a Categorical Heatmap (stand-alone, and closely based on the example in the Bokeh gallery), to which I have attached a CustomJS callback using a TapTool. The callback makes an Ajax call to a web service (with the factors from the selected cell of the Heatmap as parameters) and sets the innerHTML of a div based on the returned value. The div is created in a Jupyter notebook using a call to HTML(), or the same HTML is added manually to that produced by Bokeh via output_file(); either way, the update works as expected when a cell of the Heatmap is selected.

My problem is that I would like to clear the contents of the div when the selection is cleared (i.e. when the escape key is pressed). As I understand it, if I was using a Bokeh server, I could define a callback in Python and use “source.on_change(‘selected’, callback)” to update the plot itself (and/or linked plots and widgets) when the selection status changes. However, I don’t actually want to update the plot, only the div, and I can’t see how I can update the div using the Python callback approach.

So, in essence, my question is: Is there a way I can run a Javascript function when the selection on a plot is cleared?

Many thanks,

Francis

Yes, use CustomJS and you can run whatever arbitrary JS you want.

At the start of your callback just check whether the selection is

now empty - if it is - run your callback.

Bokeh also has a Div widget incase it's useful.
···

http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-selections
On 9/27/16 12:52 AM,
wrote:

[email protected]

Hello,

      I have a Categorical Heatmap (stand-alone, and closely

based on the example in the Bokeh gallery), to which I have
attached a CustomJS callback using a TapTool. The callback
makes an Ajax call to a web service (with the factors from the
selected cell of the Heatmap as parameters) and sets the
innerHTML of a div based on the returned value. The div is
created in a Jupyter notebook using a call to HTML(), or the
same HTML is added manually to that produced by Bokeh
via output_file(); either way, the update works as expected
when a cell of the Heatmap is selected.

      My problem is that I would like to clear the contents of

the div when the selection is cleared (i.e. when the escape
key is pressed). As I understand it, if I was using a Bokeh
server, I could define a callback in Python and use
“source.on_change(‘selected’, callback)” to update the plot
itself (and/or linked plots and widgets) when the selection
status changes. However, I don’t actually want to update the
plot, only the div, and I can’t see how I can update the div
using the Python callback approach.

      So, in essence, my question is: Is there a way I can run a

Javascript function when the selection on a plot is cleared?

Many thanks,

Francis

  You received this message because you are subscribed to the Google

Groups “Bokeh Discussion - Public” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

  To post to this group, send email to [email protected].

  To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/c7d4e0fa-362c-451e-9394-34dd0335769f%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/c7d4e0fa-362c-451e-9394-34dd0335769f%40continuum.io?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

Got it. Many thanks, Sarah!

···

On Sunday, 9 October 2016 08:35:31 UTC+1, Sarah Bird wrote:

Yes, use CustomJS and you can run whatever arbitrary JS you want.
http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-selections

At the start of your callback just check whether the selection is

now empty - if it is - run your callback.

Bokeh also has a Div widget incase it's useful.


  On 9/27/16 12:52 AM, > [email protected] wrote:

Hello,

      I have a Categorical Heatmap (stand-alone, and closely

based on the example in the Bokeh gallery), to which I have
attached a CustomJS callback using a TapTool. The callback
makes an Ajax call to a web service (with the factors from the
selected cell of the Heatmap as parameters) and sets the
innerHTML of a div based on the returned value. The div is
created in a Jupyter notebook using a call to HTML(), or the
same HTML is added manually to that produced by Bokeh
via output_file(); either way, the update works as expected
when a cell of the Heatmap is selected.

      My problem is that I would like to clear the contents of

the div when the selection is cleared (i.e. when the escape
key is pressed). As I understand it, if I was using a Bokeh
server, I could define a callback in Python and use
“source.on_change(‘selected’, callback)” to update the plot
itself (and/or linked plots and widgets) when the selection
status changes. However, I don’t actually want to update the
plot, only the div, and I can’t see how I can update the div
using the Python callback approach.

      So, in essence, my question is: Is there a way I can run a

Javascript function when the selection on a plot is cleared?

Many thanks,

Francis

  You received this message because you are subscribed to the Google

Groups “Bokeh Discussion - Public” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

  To post to this group, send email to [email protected].

  To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/c7d4e0fa-362c-451e-9394-34dd0335769f%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/c7d4e0fa-362c-451e-9394-34dd0335769f%40continuum.io?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).


Sarah Bird
Developer, Bokeh

    [
      <img alt="Continuum Analytics" src="https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000" height="30px" width="150px">
    ](http://continuum.io)