shiny.ui.Progress#

class shiny.ui.Progress(min=0, max=1, session=None)#

Initialize a progress bar.

Parameters
  • min (int) – The value that represents the starting point of the progress bar. Must be less than max.

  • max (int) – The value that represents the end of the progress bar. Must be greater than min.

  • session (Optional[Session]) – A Session instance. If not provided, it is inferred via get_current_session().

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *
import asyncio

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

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

close()

Close the progress bar.

inc([amount, message, detail])

Increment the progress bar.

set([value, message, detail])

Updates the progress panel.

Attributes

min

max

value