Interactive Jupyter Widgets not working in Jupyter Lab
Asked Answered
C

4

11

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);

enter image description here

What is the problem here, and how can I get widgets to work?

Carolinacaroline answered 1/10, 2018 at 11:39 Comment(1)
Possible duplicate of How to get ipywidgets working in Jupyter Lab?Washing
E
6

You need to install widget extension

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension --sys-prefix
Evincive answered 1/10, 2018 at 17:1 Comment(2)
!> jupyter nbextension enable --py widgetsnbextension --sys-prefix 117ms < Tue Oct 2 12:26:48 2018 Error executing Jupyter command 'nbextension': [Errno 2] No such file or directoryCarolinacaroline
This is not fixing it.Messere
P
4

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
Proprioceptor answered 1/4, 2019 at 8:35 Comment(1)
Didn't work for me - Error: Object 'jupyter.widget' not found in registryValerle
S
0

This works for me:

delete all output cells

save notebook

reload page

restart kernel

run with %matplotlib widget

Semitics answered 4/1 at 23:3 Comment(1)
This is an old post you've now tagged with a more current answer. (ipywidgets no long needs nodejs or a separate command to trigger the extension to be useful in current Jupyter.) Thanks. I'm a bit unsure though if %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?Denunciation
A
0

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

Aleppo answered 30/5 at 14:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.