req(*args, cancel_output=False)

Throw a silent exception for falsy values.

This is a convenient shorthand for throwing SilentException / SilentCancelOutputException if any of the arguments are falsy.

The term "falsy" generally indicates that a value is considered False when encountered in a logical context. We use the term a little loosely here; our usage tries to match the intuitive notions of "Is this value missing or available?", or "Has the user provided an answer?", or in the case of action buttons, "Has the button been clicked?". So False, None, 0, and "" would be examples of Falsy values.


*args: T = ()

Any number of arguments to check.

cancel_output: bool | Literal[‘progress’] = False

If True, throw SilentCancelOutputException instead of SilentException.


Type Description
T | None The first argument. If no arguments are provided, returns None.


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

## file:
from shiny import reactive, req
from import input, render, ui
from shiny.types import SafeException

ui.input_action_button("safe", "Throw a safe error")

def safe():
    # This error _won't_ be sanitized when deployed (i.e., it's "safe")
    raise SafeException(f"You've clicked {str(safe_click())} times")

ui.input_action_button("unsafe", "Throw an unsafe error")

def unsafe():
    # This error _will_ be sanitized when deployed (i.e., it's "unsafe")
    raise Exception(f"Super secret number of clicks: {str(input.unsafe())}")

    "Enter some text below, then remove it. Notice how the text is never fully removed.",

def txt_out():
    req(input.txt(), cancel_output=True)
    return input.txt()

def safe_click():

def _():
    print("unsafe clicks:", input.unsafe())
    # raise Exception("Observer exception: this should cause a crash")