express.ui.Progress
express.ui.Progress(min=0, max=1, session=None)Initialize a progress bar.
Progress creates a computation manager that can be used with with to run a block of code. Shiny will display a progress bar while the code runs, which you can update by calling the set() and message() methods of the computation manager at strategic points in the code block.
Parameters
min : int = 0-
The value that represents the starting point of the progress bar. Must be less than
max. max : int = 1-
The value that represents the end of the progress bar. Must be greater than
min. session : Optional[Session] = None-
The
Sessioninstance that the progress bar should appear in. If not provided, the session is inferred viaget_current_session.
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
import asyncio
from shiny import reactive
from shiny.express import input, render, ui
ui.input_action_button("button", "Compute")
@render.text
@reactive.event(input.button)
async def compute():
with ui.Progress(min=1, max=15) as p:
p.set(message="Calculation in progress", detail="This may take a while...")
for i in range(1, 15):
p.set(i, message="Computing")
await asyncio.sleep(0.1)
# Normally use time.sleep() instead, but it doesn't yet work in Pyodide.
# https://github.com/pyodide/pyodide/issues/2354
return "Done computing!"
Methods
| Name | Description |
|---|---|
| close | Close the progress bar. You can also use the Progress object as a context manager, which will cause the progress bar to close on exit. |
| inc | Increment the progress bar. |
| set | Opens and updates the progress panel. |
close
express.ui.Progress.close()Close the progress bar. You can also use the Progress object as a context manager, which will cause the progress bar to close on exit.
Parameters
self :-
The object instance
Note
Removes the progress panel. Future calls to set and close will be ignored.
inc
express.ui.Progress.inc(amount=0.1, message=None, detail=None)Increment the progress bar.
Like set, this updates the progress panel. The difference is that inc increases the progress bar by amount, instead of setting it to a specific value.
Parameters
self :-
The object instance
amount : float = 0.1-
The amount to increment in progress.
message : Optional[str] = None-
The message to be displayed to the user or
Noneto hide the current message (if any). detail : Optional[str] = None-
The detail message to be displayed to the user or
Noneto hide the current detail message (if any). The detail message will be shown with a de-emphasized appearance relative to message.
set
express.ui.Progress.set(value=None, message=None, detail=None)Opens and updates the progress panel.
When called the first time, the progress panel is displayed.
Parameters
self :-
The object instance
value : Optional[float] = None-
The value at which to set the progress bar, relative to
minandmax.Nonehides the progress bar, if it is currently visible. message : Optional[str] = None-
The message to be displayed to the user or
Noneto hide the current message (if any). detail : Optional[str] = None-
The detail message to be displayed to the user or
Noneto hide the current detail message (if any). The detail message will be shown with a de-emphasized appearance relative to message.