shiny.types.SilentException#

class shiny.types.SilentException#

Throw a silent exception.

Normally, when an exception occurs inside a reactive context, it’s either:

  • Displayed to the user (as a big red error message)
    • This happens when the exception is raised from an output context (e.g., shiny.render.ui())

  • Crashes the application

This exception is used to silently throw inside a reactive context, meaning that execution is paused, and no output is shown to users (or the python console).

Example

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

app_ui = ui.page_fluid(
    ui.input_text(
        "txt",
        "Enter text to see it displayed below the input",
        width="400px",
    ),
    ui.output_ui("txt_out"),
)

def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.ui
    def txt_out():
        if not input.txt():
            raise SilentException()
        return "Your input: " + input.txt()


app = App(app_ui, server)