Bokeh.documents not ready at window.onload for v>=0.12.11, cannot run javascript init functions

Hi,

I’ve been using bokeh 0.12.9 for a long time. Yesterday, I decided to switch to 0.13.0. However, I found that ‘window.Bokeh.documents’ was empty at ‘window.onload’:

I was able to do many useful things at this point, such as:

  1. change the tool_name of hover_tools

  2. call a CustomJS callback–e.g. interpret html query strings and adjust the page accordingly

I’ve attached a minimal example script to reproduce the behavior. Just do:

$ pip install ‘bokeh==0.12.10’

$ python test_bokeh_page.py

$ open my_bokeh.html # or navigate to browser etc.

$ pip install ‘bokeh==0.12.11’

$ python test_bokeh_page.py

$ open my_bokeh.html

You’ll see at the top of the page that for 0.12.10, that window.Bokeh.documents.length==1, while for bokeh 0.12.11, window.Bokeh.documents.length==0

Note in any case, once the page is fully loaded, I can interactively see that the window.Bokeh.documents array is filled. So some content is still being loaded by the browser at window.onload…

Is there anyway that I can execute something once the page is fully loaded? For example, get a customJS callback by name from the bokeh document and execute it.

Thanks,

Justin

test_bokeh_page.py (1.56 KB)

Hi,

···

On Thu, Jun 21, 2018 at 8:12 PM, griffiths1983 [email protected] wrote:

Hi,

I’ve been using bokeh 0.12.9 for a long time. Yesterday, I decided to switch to 0.13.0. However, I found that ‘window.Bokeh.documents’ was empty at ‘window.onload’:

    window.onload = function() {{
       console.log('init loaded page, bokeh documents length:', window.Bokeh.documents.length)
    }}
  </script>

I was able to do many useful things at this point, such as:

  1. change the tool_name of hover_tools
  1. call a CustomJS callback–e.g. interpret html query strings and adjust the page accordingly

I’ve attached a minimal example script to reproduce the behavior. Just do:

$ pip install ‘bokeh==0.12.10’

$ python test_bokeh_page.py

$ open my_bokeh.html # or navigate to browser etc.

$ pip install ‘bokeh==0.12.11’

$ python test_bokeh_page.py

$ open my_bokeh.html

You’ll see at the top of the page that for 0.12.10, that window.Bokeh.documents.length==1, while for bokeh 0.12.11, window.Bokeh.documents.length==0

Note in any case, once the page is fully loaded, I can interactively see that the window.Bokeh.documents array is filled. So some content is still being loaded by the browser at window.onload…

Is there anyway that I can execute something once the page is fully loaded? For example, get a customJS callback by name from the bokeh document and execute it.

this may have worked for certain scenarios of using bokeh before, but definitively wasn’t guaranteed. In fact, this led to very poor memory management when working with large plots. Currently there is only a mechanism for determining if a document was fully loaded, but you have to first obtain a such document’s handle. You can use the following code: if (doc.is_idle) do_stuff() else doc.idle.connect(do_stuff). I intent to extend this, so that one could do the same with Bokeh namespace. In the mean time, you could use setTimeout or setInterval and poll for changes to Bokeh.documents.

Mateusz

Thanks,

Justin

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/c150e01b-9485-472d-948a-877506965946%40continuum.io.

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

Hi Mateusz,

Thanks for the reply. About your suggestion of using setTimeout/setInterval. Where do you suggest I put this?

function pageInit(){ //what I want to do when document is fully loaded}

window.onload = function () {
//poll for changes with Bokeh.documents with setTimeout/Interval()
 pageInit();//after confirm that document is loaded
 }

Thanks,
Justin

···

On Monday, June 25, 2018 at 1:29:12 PM UTC-5, mateusz.paprocki wrote:

Hi,

On Thu, Jun 21, 2018 at 8:12 PM, griffiths1983 [email protected] wrote:

Hi,

I’ve been using bokeh 0.12.9 for a long time. Yesterday, I decided to switch to 0.13.0. However, I found that ‘window.Bokeh.documents’ was empty at ‘window.onload’:

    window.onload = function() {{
       console.log('init loaded page, bokeh documents length:', window.Bokeh.documents.length)
    }}
  </script>

I was able to do many useful things at this point, such as:

  1. change the tool_name of hover_tools
  1. call a CustomJS callback–e.g. interpret html query strings and adjust the page accordingly

I’ve attached a minimal example script to reproduce the behavior. Just do:

$ pip install ‘bokeh==0.12.10’

$ python test_bokeh_page.py

$ open my_bokeh.html # or navigate to browser etc.

$ pip install ‘bokeh==0.12.11’

$ python test_bokeh_page.py

$ open my_bokeh.html

You’ll see at the top of the page that for 0.12.10, that window.Bokeh.documents.length==1, while for bokeh 0.12.11, window.Bokeh.documents.length==0

Note in any case, once the page is fully loaded, I can interactively see that the window.Bokeh.documents array is filled. So some content is still being loaded by the browser at window.onload…

Is there anyway that I can execute something once the page is fully loaded? For example, get a customJS callback by name from the bokeh document and execute it.

this may have worked for certain scenarios of using bokeh before, but definitively wasn’t guaranteed. In fact, this led to very poor memory management when working with large plots. Currently there is only a mechanism for determining if a document was fully loaded, but you have to first obtain a such document’s handle. You can use the following code: if (doc.is_idle) do_stuff() else doc.idle.connect(do_stuff). I intent to extend this, so that one could do the same with Bokeh namespace. In the mean time, you could use setTimeout or setInterval and poll for changes to Bokeh.documents.

Mateusz

Thanks,

Justin

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/c150e01b-9485-472d-948a-877506965946%40continuum.io.

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