Tabs
The Tabs helper lets you organize content into multiple tabs, showing one panel at a time. It is useful for dashboards, comparisons, multi-step outputs, or grouping related results without cluttering the UI.
mr.Tabs() returns a tuple of output areas — one per tab.
On rerun, reused tab outputs are cleared by default so each tab shows the latest execution result.
Live Demo
Section titled “Live Demo”You can check the Tabs widget directly in this interactive example:
Call mr.Tabs() with a list of tab labels.
The function returns one output widget for each tab.
Basic Example
Section titled “Basic Example”Code
import mercury as mr
tabs = mr.Tabs(labels=["Overview", "Details", "Logs"])
with tabs[0]: print("Overview content")
with tabs[1]: print("Detailed results")
with tabs[2]: print("Logs and debug output")Set Active Tab
Section titled “Set Active Tab”Use the active argument to select which tab is visible initially.
Code
import mercury as mr
tabs = mr.Tabs( labels=["Train", "Validate", "Test"], active=1)
with tabs[1]: print("Validation results")Layout Position
Section titled “Layout Position”Use the position argument to control where the tabs are rendered.
The default is position="inline".
Available values:
"sidebar"— render tabs in the sidebar"inline"— render tabs in the main notebook flow (default)"bottom"— render tabs after all notebook cells
Code
mr.Tabs( labels=["Settings", "Preview"], position="sidebar")Append Previous Content
Section titled “Append Previous Content”By default, append=False, so content from the previous run is cleared before new content is written.
Set append=True when you intentionally want a tab to accumulate output across runs.
Code
tabs = mr.Tabs(labels=["Events", "Summary"], append=True)
with tabs[0]: print("This output is appended on each run")Clear Content Manually
Section titled “Clear Content Manually”Each returned tab output supports .clear().
Use it when you want to clear a tab manually from your notebook code.
Code
tabs = mr.Tabs(labels=["Events", "Summary"])
tabs[0].clear()
with tabs[0]: print("Fresh tab content")Tabs Props
Section titled “Tabs Props”labels
Section titled “labels”type: list[str]
Labels displayed in the tab header. Each label creates one tab and one output panel.
active
Section titled “active”type: int
Index of the initially active tab (0-based).
The default is 0.
position
Section titled “position”type: "sidebar" | "inline" | "bottom"
Controls where the tabs container is rendered:
- sidebar — in the sidebar
- inline — directly in the notebook output (default)
- bottom — after all notebook cells
type: string
Unique identifier used to distinguish tabs with identical arguments.
append
Section titled “append”type: bool
Controls what happens when Mercury reuses the same Tabs instance:
False— clear previous tab content before writing new content (default)True— keep previous content and append new output
mr.Tabs()returns a tuple of output widgets with.clear()methods.- Write content into a tab using
with tabs[i]: .... - Only one tab panel is visible at a time.
- By default, reruns replace previous tab content. Use
append=Trueto accumulate content. - Tabs automatically handle keyboard navigation (arrow keys, Home, End).
- Content inside tabs is responsive and constrained to the container width.