Use case for new Progress widget

Hi community, can someone please help to create a minimal example for the new Progress widget in bokeh 3.7. My use case is the indeterminate mode while a computation runs in a Python callback. Here is a non-working minimal example.

from time import sleep
from bokeh.io import curdoc
from bokeh.models import Button, Progress
from bokeh.layouts import column

def func():
    progress.disabled = False
    sleep(3) # run computation
    progress.disabled = True

button = Button(width=300, button_type='primary', label='press me')
button.on_click(func)

progress = Progress(width=300, mode='indeterminate', disabled=True)

curdoc().add_root(column(button, progress))

The Progress widget will run as soon as the application opens (a bar moves back and forth real-time) if initialized with disabled=False, however changing the same attribute in the Python callback triggered by the Button has no effect. The objective is to enable the widget while the Python callback runs, then to disable. It is important in my use case to manage the Progress widget from the Python callback.

Thank you very much for creating the new feature, and for any help you can offer here.

Please see the discussion and resolution linked below, your issue is precisely the same:

1 Like

Here is the working minimal example, for an indeterminate Progress widget in a Python callback. Thank you.

from time import sleep
from bokeh.io import curdoc
from bokeh.models import Button, Progress
from bokeh.layouts import column

def func():
    doc.add_next_tick_callback(start)
    doc.add_next_tick_callback(process)
    doc.add_next_tick_callback(close)

def process():
    sleep(3)

def start():
    progress.disabled = False
    button.label = 'start'

def close():
    progress.disabled = True
    button.label = 'press me'

button = Button(width=300, button_type='primary', label='press me')
button.on_click(func)

progress = Progress(width=300, mode='indeterminate', disabled=True)

doc = curdoc()
doc.add_root(column(button, progress))
1 Like