jupyter / dashboards_server

[RETIRED] Server that runs and renders Jupyter notebooks as interactive dashboards
Other
181 stars 48 forks source link

ipywidgets randomly missing (again) in test notebook #240

Closed parente closed 8 years ago

parente commented 8 years ago

Tasks:


Original Description:

Using:

OR:

And deploying this notebook:

https://gist.github.com/parente/bcdaab0b004d22dadd60c811240ea048

Sometimes the labels on the ipywidgets widgets go missing. Sometimes the entire widgets go missing. It varies from refresh to refresh.

Expected (seen in notebook):

screen shot 2016-05-18 at 3 01 03 pm

Result (seen in dashboard server):

screen shot 2016-05-18 at 3 00 51 pm

Worth noting

jhpedemonte commented 8 years ago

See this comment (and others in that issue) from Sylvain about potential timing issues around Label.

parente commented 8 years ago

Looks to be another ipywidgets timing bug. Can't be related to requirejs because we're now webpacking all of ipywidgets into our build to avoid https://github.com/ipython/ipywidgets/issues/561. But the consequence sure looks like the issue we reported before against ipywidgets.

/cc @SylvainCorlay @Carreau because I get the feeling the bug mentioned on standup yesterday and the timing issues we've seen are intertwined.

parente commented 8 years ago

Findings so far

Thought: We're webpacking all of ipywidgets, but loading declarative widgets asynchronously. Decl widgets also loads all of its modules async. Is the use of async require for decl widgets somehow tripping up ipywidgets thereafter?

/cc @lbustelo

SylvainCorlay commented 8 years ago

I have experienced the same timing issue in an example corresponding to

web3 example + custom widgets (asynchronously loaded model)

parente commented 8 years ago

web3 example + custom widgets (asynchronously loaded model)

Yep. Root cause here is the same as in https://github.com/ipython/ipywidgets/issues/561: when loading any modules asynchronously, classes from jupyter-js-widgets also start getting resolved asynchronously because of the logic in the utils.js loadClass and stop working properly. So it's not the async load that's the problem per se. It's some code in ipywidgets that is depending on the load promise getting resolved immediately.

More details about what's happening here in dashboard server with decl widgets vs not ...

As soon as window.requirejs.defined('jupyter-js-widgets') becomes true, loadClass function in ipywidgets starts taking the branch that uses window.require instead of immediately resolving with the webpacked version of jupyter-js-widgets. When we have a notebook that only uses ipywidgets, defined('jupyter-js-widgets')remains false because nothing requires it explicitly. This is why a notebook with only ipywidgets works fine. When we have a notebook that uses declarative widgets, defined('jupyter-js-widgets') becomes true because the declarative widgets require jupyter-js-widgets explicitly. Once defined is true, everything takes the window.require path in loadClass, including all requests for jupyter-js-widgets. This should not be a problem since the require call ultimately returns the same webpacked widgets module. But it is a problem because somehow the async require causes labels, default values, or sometimes entire widgets not to appear on the page.

@jhpedemonte is going to add more detail to https://github.com/ipython/ipywidgets/issues/561. We should continue the convo there. (This defect is just a symptom.)

parente commented 8 years ago

The remaining work here is to update to jupyter-js-services 0.10.2 and whatever version of ipywidgets ends up containing the other half of the fix (5.1.5?).

SylvainCorlay commented 8 years ago

Yeah I will continue making minor releases of ipywidgets.