1

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 2

2

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_change and js_on_change API 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 callback is unclear

  • Define JS callback as

    some_model.js_on_change = CustomJS(code="alert('hi!')")
    

    js_on_change is present only for few models

  • Code injection in DataTable's

    TableColumn(..., 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)
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.