I noticed that interactive widgets are not working in my Jupyter Lab notebooks.
The following code should produce an interactive slider but doesn't:
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
def f(x):
return x
interact(f, x=10);
What is the problem here, and how can I get widgets to work?
-
Possible duplicate of How to get ipywidgets working in Jupyter Lab?Chrisvdberge– Chrisvdberge2019年02月21日 16:10:36 +00:00Commented Feb 21, 2019 at 16:10
4 Answers 4
You need to install widget extension
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension --sys-prefix
Per the docs:
To install the JupyterLab extension you also need to run the command below in a terminal which requires that you have nodejs installed.
jupyter labextension install @jupyter-widgets/jupyterlab-manager
I think it's the latter nodejs requirement that you are missing e.g. with Conda, first run:
conda install nodejs
1 Comment
This works for me:
delete all output cells
save notebook
reload page
restart kernel
run with %matplotlib widget
1 Comment
%matplotlib widget is really needed though? As discussed here that is related to using interactive plots with ipympl. I don't see why ipywidgets would need a magic command that set the matplotlib backend?When using Anaconda
- open Anaconda.Navigator
- open Environments from the left Navigation panel
- select base(root) (base root is fine for testing, not for production!)
- search for: "nbex"
for whatever reasons the package widgetsnbextension is not pre-installed.
- tick the box left to the package and "Apply"
- make sure the
base (root)environment is selected - start Jupyterlab
the widgets should work now
Comments
Explore related questions
See similar questions with these tags.