express.ui.panel_conditional
**kwargs) express.ui.panel_conditional(condition,
Context manager for a conditional panel
This function wraps panel_conditional.
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.
****kwargs** : TagAttrValue = {}
-
Attributes to place on the panel tag.
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.
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
from shiny.express import ui
ui.input_checkbox("show", "Show radio buttons", False)
with ui.panel_conditional("input.show"):
ui.input_radio_buttons("radio", "Choose ", ["slider", "select"])
with ui.panel_conditional("input.show && input.radio === 'slider'"):
ui.input_slider("slider", None, min=0, max=100, value=50)
with ui.panel_conditional("input.show && input.radio === 'select'"):
ui.input_select("select", None, ["A", "B", "C"])