8

Jupyter widgets, like a HTML progress bar, vanish when a notebook browser window is refreshed (or when one reconnects to a notebook remotely). I'm trying to see how they might be made to persist and re-render when the window is refreshed.

Let's say I have Jupyter set up with widgets like this:

jupyter nbextension enable --py widgetsnbextension

And then I launch a notebook like this:

import time

import ipykernel
import ipywidgets
import IPython
import jupyter
import notebook
import tqdm
import tqdm.notebook
import widgetsnbextension

print('ipykernel version: ', ipykernel.__version__)
print('ipywidgets version: ', ipywidgets.__version__)
print('IPython version: ', IPython.__version__)
print('Jupyter version: ', jupyter.__version__)
print('Jupyter notebook version: ', notebook.__version__)
print('tqdm version: ', tqdm.__version__)
print('widgetsnbextension version: ', widgetsnbextension.__version__)

The printout of versions I get when I do this is as follows:

ipykernel version:  5.1.3
ipywidgets version:  7.5.1
IPython version:  7.9.0
Jupyter version:  1.0.0
Jupyter notebook version:  6.0.2
tqdm version:  4.40.0
widgetsnbextension version:  3.5.1

Now after those imports, I set a progress bar widget going:

for i in tqdm.notebook.tqdm(list(range(0, 1000))):
    time.sleep(1)

So, I see a nice graphical progress bar like this:

Now, if I close the window and open it again, or simply refresh the page, suddenly this graphical progress bar vanishes and I am left with the text like HBox(children=(FloatProgress(value=0.0, max=1000.0), HTML(value=''))):

What's going wrong? How can I get my lovely widgets to persist?

BlandCorporation
  • 1,324
  • 1
  • 15
  • 33
  • 2
    I always thought it was just the way it is, and tried to not refresh the page when I have a widget on the page. But there are times when I do need to refresh, and if there is a way to make them persist, I would love to know as well. – Kevin Lee Feb 06 '20 at 23:51

0 Answers0