ui.panel_conditional

ui.panel_conditional(condition, *args, **kwargs)

Create a conditional panel.

Show UI elements only if a JavaScript condition is true.

Parameters

condition: str

A JavaScript expression that will be evaluated repeatedly to determine whether the panel should be displayed.

*args: TagChild | TagAttrs = ()

UI elements to include inside the panel.

**kwargs: TagAttrValue = {}

Attributes to place on the panel tag.

Returns

Type Description
Tag A UI element.

Note

In the JS expression, you can refer to input and output JavaScript objects that contain the current values of input and output. For example, if you have an input with an id of foo, then you can use input.foo to read its value. (Be sure not to modify the input/output objects, as this may cause unpredictable behavior.)

You are not recommended to use special JavaScript characters such as a period . in the input id’s, but if you do use them anyway, for example, id = "foo.bar", you will have to use input["foo.bar"] instead of input.foo.bar to read the input value.

Tip

A more powerful (but slower) way to conditionally show UI content is to use ui.

See Also

Examples

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

## file: app.py
from shiny import App, Inputs, Outputs, Session, ui

app_ui = ui.page_fluid(
    ui.input_checkbox("show", "Show radio buttons", False),
    ui.panel_conditional(
        "input.show", ui.input_radio_buttons("radio", "Choose ", ["slider", "select"])
    ),
    ui.panel_conditional(
        "input.show && input.radio === 'slider'",
        ui.input_slider("slider", None, min=0, max=100, value=50),
    ),
    ui.panel_conditional(
        "input.show && input.radio === 'select'",
        ui.input_select("select", None, ["A", "B", "C"]),
    ),
)


def server(input: Inputs, output: Outputs, session: Session):
    pass


app = App(app_ui, server)