Tqdm

Download this notebook from GitHub (right-click to download).


import time

import numpy as np
import pandas as pd
import panel as pn

from panel.widgets import Tqdm

pn.extension()

The Tqdm indicator wraps the well known tqdm progress indicator and displays the progress towards some target. You can use it in the notebook or in your Panel web app.

Tqdm

Parameters:

  • layout (Column or Row): The layout of the progress indicator and the text_pane.

  • max (int): The maximum progress value.

  • progress (Progress): The Progress indicator to display the progress on.

  • text (int): The current text being output by tqdm.

  • text_pane (Str): The Pane displaying the progress text.

  • value (int or None): The current value towards the progress.

  • write_to_console (bool): Whether or not to also write to the console, only works on server.

For layout and styling related parameters see the customization user guide. For a general introduction to tqdm and lots of examples checkout the tqdm github page.


To use the Tqdm indicator instantiate the object and then use the resulting variable just like you would use tqdm.tqdm, i.e. you can iterate over any iterable:

tqdm = Tqdm()

def run_loop(*events, timeout=0.2):
    for i in tqdm(range(0,10), desc="My loop bar", leave=True, colour='#666666'):
        time.sleep(timeout)
        
run_loop(timeout=0.01)

tqdm

Most of the parameters supported by tqdm can be passed to the call method of the Tqdm indicator.

Click the button below to see the progress bar update (if you viewing this on a live kernel):

button = pn.widgets.Button(name="Run Loop", button_type="success")
button.on_click(run_loop)
button

Nesting

When nesting Tqdm indicators using the margin parameter allows visually indicating the level of nesting.

tqdm_outer = Tqdm()
tqdm_inner = Tqdm(margin=(0, 0, 0, 20))

def run_nested_loop(*events, timeout=0.05):
    for i in tqdm_outer(range(10)):
        for j in tqdm_inner(range(10)):
            time.sleep(timeout)
            
run_nested_loop(timeout=0.01)

pn.Column(tqdm_outer, tqdm_inner)
button = pn.widgets.Button(name="Run Nested Loop", button_type="success")
button.on_click(run_nested_loop)
button

Pandas

To use the tqdm pandas integration you can activate it by calling tqdm.pandas with all the configuration options. Once activated the progress_apply method is available on a pandas.DataFrame:

tqdm_pandas = Tqdm(width=500)

# Register Pandas. This gives DataFrame.progress_apply method
tqdm_pandas.pandas(desc="Pandas Progress")

df = pd.DataFrame(np.random.randint(0, 100, (100000, 600)))

def run_df(*events):
    df.progress_apply(lambda x: x**2)
    
run_df()

tqdm_pandas
pandas_button = pn.widgets.Button(name="Run Pandas Apply", button_type="success")
pandas_button.on_click(run_df)
pandas_button
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).