shiny.ui.panel_conditional#

shiny.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 (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – UI elements to include inside the panel.

  • kwargs (Union[str, float, bool, None]) – Attributes to place on the panel tag.

Return type

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

ui, output_ui

Example

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

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("slider", None, ["A", "B", "C"]),
    ),
)

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


app = App(app_ui, server)