5

I am coding an interface using the Jupyter widgets where the user configures a bunch of settings and then clicks a "Run" button. On clicking, this button calls a function implemented in another module. That function takes some time to run, so I added to it a progress bar using the tqdm package. Unfortunately, when I click "Run", this progress bar is now displayed in another terminal, rather than within the output of the cell. Is there a way to have the bar be displayed within the same cell output?

GuPe
  • 277
  • 2
  • 9

1 Answers1

3

There is a submodule of tqdm with jupyter integration: https://github.com/tqdm/tqdm#ipython-jupyter-integration. If you already have widgets enabled it should work out of the box. Just replace any tqdm calls with their equivalent from the tdqm.notebook submodule, i.e. import

from tqdm.notebook import trange, tqdm

instead of

from tqdm import trange, tqdm

This assumes you are actually calling tqdm directly in the notebook and the call is not buried in your other module code. If that's the case you might need to pass an argument through or patch the tqdm calls.

Simon Bowly
  • 1,003
  • 5
  • 10
  • I am already using the first line. But I already found a solution. Just attach whatever output to an Output widget as detailed here: https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html – GuPe Jun 23 '21 at 08:21
  • `tqdm.auto` is also handy – krassowski Jun 23 '21 at 09:40
  • The loading bars with tqdm.notebook.tqdm did not show any progress for me, until I ran: `pip install ipywidgets` , then `jupyter nbextension enable --py widgetsnbextension`, and then restart Jupyter. ([Credits](https://vucavucalife.com/en/jupyter-notebook-de-miyasui-tqdm/)) – dasWesen Feb 10 '22 at 10:05
  • Brilliant answer - works out the box! – jtlz2 Apr 05 '22 at 08:10