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

Context manager for a conditional panel

This function wraps panel_conditional.

Show UI elements only if a JavaScript condition is true.


condition: str

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

**kwargs: TagAttrValue = {}

Attributes to place on the panel tag.


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 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 = "", you will have to use input[""] instead of to read the input value.


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


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

## file:
from import ui

ui.input_checkbox("show", "Show radio buttons", False)

with ui.panel_conditional(""):
    ui.input_radio_buttons("radio", "Choose ", ["slider", "select"])

with ui.panel_conditional(" && === 'slider'"):
    ui.input_slider("slider", None, min=0, max=100, value=50)

with ui.panel_conditional(" && === 'select'"):
    ui.input_select("select", None, ["A", "B", "C"])