ui.Progress

ui.Progress(self, 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 Session instance that the progress bar should appear in. If not provided, the session is inferred via get_current_session.

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
import asyncio

from shiny import App, Inputs, Outputs, Session, reactive, render, ui

app_ui = ui.page_fluid(
    ui.input_action_button("button", "Compute"),
    ui.output_text("compute"),
)


def server(input: Inputs, output: Outputs, session: Session):
    @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!"


app = App(app_ui, server)

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

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

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 None to hide the current message (if any).

detail: Optional[str] = None

The detail message to be displayed to the user or None to hide the current detail message (if any). The detail message will be shown with a de-emphasized appearance relative to message.

set

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 min and max. None hides the progress bar, if it is currently visible.

message: Optional[str] = None

The message to be displayed to the user or None to hide the current message (if any).

detail: Optional[str] = None

The detail message to be displayed to the user or None to hide the current detail message (if any). The detail message will be shown with a de-emphasized appearance relative to message.