jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.11k stars 947 forks source link

ipywidgets not working with JupyterLab examples/notebook sample code #2361

Open languy opened 5 years ago

languy commented 5 years ago

Hi, I read all other issues in Jupyterlab and also googled the problem, but none of the solutions mentioned worked (most of them upgrading to the latest version of the various utilities/packages). This is similar to this issue, but I'm not sure whether it is the same, so rather than adding noise to that one, I decided to open a new one. Apologies if it's a duplicate.

Setup:

  1. I have a jupyter server running: image
  2. I made one modification of the examples/notebook sample code to point to my server: line 40: let manager = new ServiceManager({ serverSettings: ServerConnection.makeSettings({ baseUrl: "<my jupyter server url here" }) });
  3. In examples/notebook: npm install, npm run build
  4. Copy the build result and serve in a separate webapp using webpack-dev-server

Everything renders fine in the notebook except I get this error if I want to execute some ipywidget code like this one: import ipywidgets out = ipywidgets.Dropdown(options=['1', '2', '3'], value='2', description='Number') display(out)

image

And the result renders as: Dropdown(description='Number', index=1, options=('1', '2', '3'), value='2')

If I open the notebook from the native's jupyterlab app: http://myserver:port/lab? Then it renders fine, which tells me that there must be a bug in the sample code of the packages it depends on, but the general jupyter server config/installation should work fine.

I tried the few things below, but no luck:

At this point, I'm running out of ideas other than deep diving in the code to understand how the http://server/lab? frontend code differs from the examples/notebook.

Any ideas?

languy commented 5 years ago

This is what I found out. This broadly applies to all jupyterlab extensions: I was mainly focused on getting ipywidgets and gmap to work.

Conclusions:

The result of this activation hangs off the docRegistry that is used by the notebook example.

If you're looking into doing the same, start from index.out.js and include all the methods that get called in your code. Most of the code is contained in these files: @phospor/application/src/index.ts jupyterlab/staging/build/index.out.js packages/application/src/lab.ts

Lessons learned: Obviously, duplicating jupyterlab and @phospor code and hardcoding package isn't gonna work long-term.

jasongrout commented 5 years ago

The next version of the jupyterlab widget manager will use a different mechanism for activating rendering widgets in a notebook, which may make it easier to use in the standalone notebook example.

Thanks very much for deep-diving into this and posting your comprehensive results. Do you mind if I reopen this so we can continue exploring this in the future?

languy commented 5 years ago

Happy to hear that this part is getting improvements. By all means, let's reopen the issue :). I'd be happy to provide more details about my use case, if that helps.

pplonski commented 8 months ago

Hi @languy, @jasongrout,

I've got very similar problem. I would like to run ipywidgets in examples/cell. Here is my output: image

I was trying to enable extension: image

Is there any way to enable ipywidgets in examples? What should be added?