Call bokeh callback on page load

Hi,

This was asked here:

https://groups.google.com/a/continuum.io/d/topic/bokeh/MbDfPa4DNcc/discussion

So is still not possible to directly configure a callback to be executed upon page load? In case it is not, could somebody suggest a javascript solution? Or someother potential solution? Basically I would like to have my page rendering dependent on a url query string. So a bit about what I do.

I have an application that creates static web-pages using bokeh. I save the bokeh produced javascript file via:

bokeh.embed.components(my_layout,wrap_script=False)

I then insert the script into my html page like:

So can I directly use javascript in the div element above to invoke the customJS element that is in the ‘my_bokeh_page.js’? getElementByID?

Thanks,

Justin

Ok,

So maybe something along the lines of:

window.onload = function() {

window.Bokeh.documents[0]._all_models[“Custom_JS_ID”].execute()

}

Then if cb_obj is null, I know it is a page refresh situation.

In case there are other ways to call a callback on page load, please let me know.

Thanks,

Justin

···

On Wednesday, March 21, 2018 at 1:16:16 PM UTC-5, griffiths1983 wrote:

Hi,

This was asked here:

https://groups.google.com/a/continuum.io/d/topic/bokeh/MbDfPa4DNcc/discussion

So is still not possible to directly configure a callback to be executed upon page load? In case it is not, could somebody suggest a javascript solution? Or someother potential solution? Basically I would like to have my page rendering dependent on a url query string. So a bit about what I do.

I have an application that creates static web-pages using bokeh. I save the bokeh produced javascript file via:

bokeh.embed.components(my_layout,wrap_script=False)

I then insert the script into my html page like:

So can I directly use javascript in the div element above to invoke the customJS element that is in the ‘my_bokeh_page.js’? getElementByID?

Thanks,

Justin

1 Like

Thank you Justin, very useful insight ! It seems to still work in Bokeh 2.0.2 with

window.onload = function(){
        let myScript = window.Bokeh.documents[0].get_model_by_name('scriptName');
        myScript.execute();
    }

Edited to reflect p-himik comment.

Instead of using private _all_models_by_name._dict, you should instead use get_model_by_name.

1 Like