class shiny.types.SafeException#

Throw a safe exception.

When shiny.App.SANITIZE_ERRORS is True (which is the case in some production environments like RStudio Connect), exceptions are sanitized to prevent leaking of sensitive information. This class provides a way to generate an error that is OK to be displayed to the user.


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

app_ui = ui.page_fluid(ui.output_ui("safe"), ui.output_ui("unsafe"))

def server(input: Inputs, output: Outputs, session: Session):
    def safe():
        raise SafeException("This is a safe exception")

    def unsafe():
        raise Exception("This is an unsafe exception")

app = App(app_ui, server)
app.sanitize_errors = True