Skip to content

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.

You can check the Tabs widget directly in this interactive example:

🚀 Load interactive demo Hover to start

Call mr.Tabs() with a list of tab labels. The function returns one output widget for each tab.

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")

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")

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"
)

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")

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")

type: list[str]

Labels displayed in the tab header. Each label creates one tab and one output panel.


type: int

Index of the initially active tab (0-based). The default is 0.


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.


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=True to accumulate content.
  • Tabs automatically handle keyboard navigation (arrow keys, Home, End).
  • Content inside tabs is responsive and constrained to the container width.