Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ipywidgets working in Jupyter Lab?

In Jupyter Notebook, ipywidgets work fine, however they seem to not work in Jupyter Lab (which is supposedly better than Notebook).

I followed these directions.

Step 1: Installed Node.js (https://nodejs.org/en/)

Step 2: Installed requirements on Python 3 with conda:

conda install -c conda-forge ipywidgets
jupyter labextension install @jupyter-widgets/jupyterlab-manager

Unfortunately, basic widgets do not work inside the jupyter lab notebook:

enter image description here

like image 322
user5601 Avatar asked Mar 28 '18 19:03

user5601


People also ask

Does Anaconda have Ipywidgets?

anaconda / packages / ipywidgets 5. 2 ipywidgets are interactive HTML widgets for Jupyter notebooks and the IPython kernel.

Why is JupyterLab not working?

Jupyter doesn't load or doesn't work in the browserTry disabling any browser extensions and/or any Jupyter extensions you have installed. Some internet security software can interfere with Jupyter.

What is Python Ipywidgets?

IPyWidgets is a Python library of HTML interactive widgets for Jupyter notebook. Each UI element in the library can respond to events and invokes specified event handler functions. They enhance the interactive feature of Jupyter notebook application.


2 Answers

JupyterLab now prefers a model where arbitrary javascript is no longer allowed to be embedded in a cell's output, which is how many interactive Jupyter Notebook modules used to work. They now ask that modules with interactivity create a JupyterLab extension. ipywidgets provides @jupyter-widgets/jupyterlab-manager extension which satisfies this requirement.

When using ipywidgets 7.6 or newer in JupyterLab 3.0 or newer you do not need to do anything: it is installed by default. You can check if this is installed by running:

jupyter labextension list

which should include a line like:

@jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)

If you are using JupyterLab 1 or 2 (or old version of ipywidgets) you need to install this extension manually by running this on your command line (which assumes you already have NodeJS installed):

jupyter labextension install @jupyter-widgets/jupyterlab-manager
like image 61
scnerd Avatar answered Oct 08 '22 04:10

scnerd


I had the same pbm, and tried this solution (hope it can help others):

The jupyter labextension install @jupyter-widgets/jupyterlab-manager gave this kind of error in my case:

> /Users/user/.nvm/versions/node/v8.7.0/bin/npm pack @jupyter-widgets/jupyterlab-manager
jupyter-widgets-jupyterlab-manager-0.35.0.tgz

Errored, use --debug for full output:
ValueError:
"@jupyter-widgets/[email protected]" is not compatible with the current JupyterLab
Conflicting Dependencies:
JupyterLab              Extension            Package
>=0.15.4-0 <0.16.0-0    >=0.16.0-0 <0.17.0-0 @jupyterlab/application
>=1.1.4-0 <2.0.0-0      >=2.0.0-0 <3.0.0-0   @jupyterlab/services
>=0.15.4-0 <0.16.0-0    >=0.16.0-0 <0.17.0-0 @jupyterlab/rendermime
>=0.15.4-0 <0.16.0-0    >=0.16.0-0 <0.17.0-0 @jupyterlab/notebook

Then, what I did is to use a previous version 0.34 instead of 0.35: jupyter labextension install @jupyter-widgets/[email protected]

In fact, according to this, sometime teams get time to consider the last version.

UP (according to comments): You can check jupyter lab --version and find match on its version compatibility.

And it works now !

enter image description here

like image 16
4givN Avatar answered Oct 08 '22 03:10

4givN