microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.27k stars 280 forks source link

Duplicate output when using nested widgets.Output #14498

Open DonJayamanne opened 11 months ago

DonJayamanne commented 11 months ago

Run a notebook with the following cells

import ipywidgets as widgets
from IPython.display import display

out = widgets.Output()
out
@out.capture()
def function_with_captured_output():
    print('First output widget')

function_with_captured_output()
out2 = widgets.Output()
caption = widgets.Label(value='Label Widget')
textbox = widgets.Text()
widgets.link((caption, 'value'), (textbox, 'value'))

@out.capture()
def function_with_captured_output():
    display(out2)
    display(caption)
    display(textbox)

function_with_captured_output()
@out2.capture()
def function_with_captured_output2():
    print('Second output widget')

function_with_captured_output2()

When running the last cell, the output Second output widget should ideally be displayed only inside an output widget nested withinm the first. That works, however, we also display a completely second output item, and thats incorrect. Basically the output Second output widget is duplicated.

This is due to the special case handling of output widgets in Jupyter lab.

ybagdasa commented 10 months ago

I have a similar/same problem:

from IPython.display import display,clear_output
from ipywidgets import interact
import matplotlib.pyplot as plt
import ipywidgets as widgets

out = widgets.Output()
def overlay_fits():
    def show_fit(i):
        with out:
            clear_output()
            display(f'this is happening twice: fit{i}')

    n = 10
    interactive_image = interact(show_fit,i=(0,n-1));

ii = overlay_fits()
out

Screenshot from 2023-10-17 16-14-50

Extension Author (truncated) Version
jupyter-keymap ms- 1.1.2
remote-containers ms- 0.315.1
remote-ssh ms- 0.106.5
remote-ssh-edit ms- 0.86.0
remote-wsl ms- 0.81.8
vscode-remote-extensionpack ms- 0.24.0
remote-explorer ms- 0.4.1
remote-server ms- 1.4.3
python ms- 2023.18.0
vscode-pylance ms- 2023.10.20
jupyter ms- 2023.9.1102792234
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.17
vscode-jupyter-cell-tags ms- 0.1.8
vscode-jupyter-slideshow ms- 0.1.5

Selected Jupyter core packages... IPython : 8.14.0 ipykernel : 6.25.0 ipywidgets : 8.1.0 jupyter_client : 8.3.0 jupyter_core : 5.3.1 jupyter_server : 2.7.0 jupyterlab : 4.0.5 nbclient : 0.8.0 nbconvert : 7.7.3 nbformat : 5.9.2 notebook : 7.0.2 qtconsole : not installed traitlets : 5.9.0

vttrifonov commented 6 months ago

same here

image
vttrifonov commented 6 months ago

In my case the issue was resolved by restart of VSCode... Something was registered twice

alexjnelson commented 5 months ago

In my case the issue was resolved by restart of VSCode... Something was registered twice

This was the case for me as well. Thanks for pointing it out