Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code does not render ipywidgets correctly

I am having issue using Visual Studio Code. the code seem to have issue with ipywidgets. the code is below (very simple interactive chart)

from ipywidgets import interact
import ipywidgets as widgets
import numpy as np
import plotly.graph_objects as go
@interact
def foo(beta=(-10,10,1)):
    myx = np.arange(0,100,1)
    myy = myx *beta 
    print ('debug:',myy)
    fig = go.FigureWidget()
    fig.add_scatter(x= myx, y=myy)
    fig.show()

the same code works just as expected in Jupyter Notebook. I dig further and it seems:

"widgets require us to download supporting files from a 3rd party website. Error loading plotlywidget: ^4.14.3

https://github.com/microsoft/vscode-jupyter/wiki/IPyWidget-Support-in-VS-Code-Python

This is where I got stuck.. What's the next then to fix this issue?

any guidance much appreciated

thanks

like image 286
cocojim Avatar asked Dec 02 '25 07:12

cocojim


2 Answers

Some of the issues I've seen reported seem to have started after the release of ipywidgets 8.

I don't understand exactly what's broken (or if it's broken), but downgrading to version 7.7.1 fixed all issues I was having.

If you want to try it as well, you can run: pip install -U ipywidgets==7.7.1

like image 158
Lucas Farias Avatar answered Dec 04 '25 23:12

Lucas Farias


something that helped me (even after v8 was supported by VS Code) was simple but not so intuitive : run the jupyter notebook in the browser
just do a simple jupyter notebook path/to/file.ipynb and run it (even if there's errors)
then relaunch VS Code window (F1 -> Developer: Reload Window) and retry
for me it magically fixes it ^^

like image 41
EDM115 Avatar answered Dec 04 '25 23:12

EDM115