clstaudt
clstaudt

Reputation: 22438

Interactive Jupyter Widgets not working in Jupyter Lab

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?

Upvotes: 11

Views: 11705

Answers (4)

PeetsB
PeetsB

Reputation: 73

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

Upvotes: 0

impulsive
impulsive

Reputation: 1

This works for me:

delete all output cells

save notebook

reload page

restart kernel

run with %matplotlib widget

Upvotes: 0

ultra909
ultra909

Reputation: 1748

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

Upvotes: 4

varun vasudevan
varun vasudevan

Reputation: 86

You need to install widget extension

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension --sys-prefix

Upvotes: 6

Related Questions