Bokeh widgets call CustomJS and Python callback for single event?

I have a Bokeh application that uses Python callbacks for various widget events. With some events, I would like to execute JavaScript code before doing a Python function callback. Is it possible?

In this case, the Python callback potentially works for a long time, and I would like to start and stop the Jinncript spinner object before and after the execution of the long Python code.

+5
source share
1 answer

busy / done events (to include things like trigger clips or other user interface events) are scheduled for one of the next two releases. (I hope that they will turn into 0.12.6 , but if they will not be in 0.12.7 .)

At the same time, it is best to use some kind of "dummy" model to launch a CustomJS . For example, you can add an invisible glyph and run CustomJS any property on it as a proxy server for a busy event. It is inconvenient but useful.

Here is a very crude example. The first warning will appear immediately. Close it, the following warning will appear after 5 seconds.

 import time from bokeh.io import curdoc from bokeh.layouts import column from bokeh.models import Button, CustomJS from bokeh.plotting import figure p = figure() p.circle([1,2,3,4,5], [2,6,3,1,6]) dummy = p.circle([1], [2], alpha=0) dummy.glyph.js_on_change('size', CustomJS(code=""" alert(cb_obj.size.value) """)) b = Button() def cb(): dummy.glyph.size = 10 time.sleep(5) dummy.glyph.size = 20 b.on_click(cb) curdoc().add_root(column(b, p)) 
+6
source

Source: https://habr.com/ru/post/1268271/


All Articles