ipython-contrib / jupyter_contrib_nbextensions

A collection of various notebook extensions for Jupyter
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest
Other
5.22k stars 806 forks source link

Initialization cell displays widgets twice #1056

Open codingS3b opened 7 years ago

codingS3b commented 7 years ago

When creating an input cell on a jupyter notebook that displays an ipywidget and marking this cell as Initialization cell, the widget is rendered twice on my machine.

See the following example:

from ipywidgets import widgets
from IPython.display import display

def print_hello(b=None):
    print("hello")

my_button = widgets.Button(description="press it")
my_button.on_click(print_hello)
display(my_button)

However it seems to work correctly when no widgets are involved:

def f(x):
    return x + 3

print(f(5))

widget_init_cell

Maybe @jcb91 could have a look at this?

Tested with

ax3l commented 7 years ago

Having the same setup, don't have the problem in the older Firefox ESR 52.3.0 (64-bit) on Debian 9.1 (stretch)

codingS3b commented 7 years ago

Tried again with chromium 60.0.3112.78 running on Ubuntu.16.04 and it seems to be working correctly there as well.

ax3l commented 7 years ago

I downloaded a Firefox 55.0.1 (64bit) for Linux and also can't reproduce it there. Any Firefox Extensions/Plugins you have installed?

jcb91 commented 7 years ago

apologies for the delay looking at this @codingS3b. So far, this seems to be working ok for me in Chrome 59.0.3071.115 (Official Build) (64-bit) and FF 55.0.2 (64-bit) on Ubuntu 16.0.4...

jcb91 commented 7 years ago

Also, what's your jupyter notebook --version?

codingS3b commented 7 years ago

Concerning plugins I use Adblock Plus but disabled it for testing and the google analytics deactivation add-on but that's it. My jupyer notebook version is 5.0.0. I also tried this again using Chromium 60.0.3112.78 on Ubuntu 16.04 and got the same behaviour as with firefox.

I have to add that the widgets are rendered correctly sometimes I refresh the notebook using F5 but sometimes not. Strange thing...

BarbaraPr commented 6 years ago

I have the same problem as codingS3b .. widgets appear twice when executed by an initialization cell

jcb91 commented 6 years ago

I'm still unable to reproduce this. Combined with the intermittent observations, this leads me to suspect a timing issue, maybe some race condition somewhere. @BarbaraPr what versions of everything are you running?

Are all of you running the server on the same machine as the browser, or is the notebook server running on a remote machine?

codingS3b commented 6 years ago

I have now tried both versions with firefox and chromium, here are my experiences:

Chromium:

Firefox:

Would a screenshot from the browser debugging section help you in some way?

jcb91 commented 6 years ago

Thanks @codingS3b, so from that it seems like maybe this issue is more likely to trigger when the notebook is loaded quickly (I asked about local/remote servers because in the past I've found that the extra time required to get the notebook from the remote server can affect timing-related bugs).

Would a screenshot from the browser debugging section help you in some way?

I'm not sure, really :laughing: I'm still at a loss for what could cause this. However, I suspect this has more to do with how widgets are implemented (somehow the cell clearing its outputs on execution is not happening correctly?!) than with init_cell, which after all just queues the cells for regular execution :thinking:

aseem-hegshetye commented 6 years ago

I had same issue when running notebook on ec2 GPU instance. I had same notebook running on localhost too and synced through dropbox. so I shutdown the notebook on remote ec2 instance. Then I shut down same notebook on localhost. Then restarted it on ec2 only, and it worked.

Geek4ray commented 2 years ago

Same issue on VSCode Jupyter Notebook.

Elektriman commented 1 year ago

In jupyter notebook if your display() call is the last line of the cell jupyter will automatically print its returning value. So its displaying one time because of the call of the display function and a second time because the Output widget is returned by the display() function and is then being printed by jupyter. Adding an empty print() statement at the end fixed it for me.