How to trigger execution of arbitrary JavaScript code in browser from Bokeh Server? Is the simplest way to create hidden button and then 'trigger' it?
2 Answers
From Bryan Van de Ven @bryevdv Mar 08 20:52
@Sklavit you will probably want to wait for bokeh/bokeh#5941
From description:
The API will be very similar to the existing
on_changeandjs_on_changeAPI used to register callbacks triggered by property changes.
As for my question on 2017-03-09, there are several way to trigger JS code from server:
Define JS callback as
some_model.callback = CustomJS(code="alert('hi!')")What is triggering
callbackis unclearDefine JS callback as
some_model.js_on_change = CustomJS(code="alert('hi!')")js_on_changeis present only for fewmodelsCode injection in
DataTable'sTableColumn(..., formatter=HTMLTemplateFormatter(template="<% alert('hi!') %>"))
My current solution Create hidden holder
callback_holder = PreText(text='', css_classes=['hidden'])
callback = CustomJS(args={}, code='alert(cb_obj.text);')
callback_holder.js_on_change('text', callback)
And then in other part of application:
def update():
callback_holder.text = 'data for JS code'
curdoc().add_next_tick_callback(update)
Comments
You might want to use templates. An example of how to use templates for bokeh-server app can be found here:
https://github.com/bokeh/bokeh/tree/master/examples/app/crossfilter
1 Comment
templates are static declaration of page content. Question is about dynamic trigger from server to page.