Expander
The Expander helper lets you hide and show a block of content under a clickable header. It is useful for optional settings, advanced parameters, explanations, or details that should not be visible by default.
mr.Expander() returns an output area, so you can write content into it using a with block.
Live Demo
Section titled “Live Demo”You can check the Expander widget directly in this interactive example:
Call mr.Expander() to create an expander section.
The function returns an output widget you can write into.
Basic Example
Section titled “Basic Example”Code
import mercury as mr
details = mr.Expander(label="Details")
with details: print("Hidden content")Expanded by Default
Section titled “Expanded by Default”Use expanded=True to open the expander on first render.
Code
import mercury as mr
details = mr.Expander( label="Advanced settings", expanded=True)
with details: print("Shown immediately")Common Pattern: Advanced Options
Section titled “Common Pattern: Advanced Options”Code
import mercury as mr
# Basic controlsname = mr.TextInput(label="Name")
# Advanced sectionadvanced = mr.Expander(label="Advanced")
with advanced: threshold = mr.NumberInput(label="Threshold", value=0.5, min=0.0, max=1.0, step=0.05) refresh = mr.Checkbox(label="Auto-refresh")Expander Props
Section titled “Expander Props”type: string
Text displayed in the expander header.
The default is "Details".
expanded
Section titled “expanded”type: bool
If True, the expander starts in the open state.
The default is False.
type: string
Unique identifier used to distinguish expanders with identical arguments.
mr.Expander()returns an output area. Put content inside usingwith.- The expander uses a single unified border and smooth open/close animation.
- Use expanders for optional or advanced settings to keep the UI clean.