Skip to content

Columns

The Columns helper lets you create a responsive row of output areas (columns) inside a Mercury App. It is useful for building dashboards, side-by-side comparisons, charts grids, or multi-panel layouts.

Each column is returned as an Output widget, so you can write into it using a with block. On rerun, reused column outputs are cleared by default so the layout shows the latest execution result.

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

🚀 Load interactive demo Hover to start

Call mr.Columns() to create a row of columns. The function returns a tuple of output widgets — one for each column.

Code

import mercury as mr
col1, col2 = mr.Columns(2)
with col1:
print("Left column")
with col2:
print("Right column")

Code

c1, c2, c3 = mr.Columns(3)
with c1:
print("Column 1")
with c2:
print("Column 2")
with c3:
print("Column 3")

Pass a list of positive numbers to create columns with proportional widths. For example, [0.4, 0.6] creates two columns where the first takes about 40% and the second takes about 60% of the available row space.

Code

left, right = mr.Columns([0.4, 0.6])
with left:
print("40% column")
with right:
print("60% column")

The values are treated as ratios, so [40, 60], [0.4, 0.6], and [2, 3] all work.

Use min_width to control how narrow a column can become. When there is not enough horizontal space, columns automatically wrap to the next row.

Code

c1, c2, c3 = mr.Columns(
n=3,
min_width="240px"
)

Control spacing between columns using the gap argument.

Code

c1, c2 = mr.Columns(
n=2,
gap="32px"
)

You can control column borders explicitly or let the theme decide.

Examples

# Theme-based borders (default)
mr.Columns(2)
# Custom border
mr.Columns(2, border="1px solid lightgray")
# No borders
mr.Columns(2, border="")

Use the position argument to control where the columns are displayed. The default is position="inline".

Available positions:

  • "sidebar" — display columns in the sidebar
  • "inline" — display columns in the main notebook output (default)
  • "bottom" — display columns after all notebook cells

Code

mr.Columns(
n=2,
position="bottom"
)

By default, append=False, so content from the previous run is cleared before new content is written. Set append=True when you intentionally want to keep previous output and append new content on each run.

Code

col1, col2 = mr.Columns(2, append=True)
with col1:
print("This output is appended on each run")

Each returned column is an output widget and supports .clear(). Use it when you want to clear a column manually from your notebook code.

Code

col1, col2 = mr.Columns(2)
col1.clear()
with col1:
print("Fresh content")

type: int | list[float]

Number of equal-width columns, or a list of proportional widths.

Examples:

  • 2 — two equal-width columns
  • [0.4, 0.6] — two columns with a 40/60 width ratio
  • [1, 2, 1] — three columns with a 1/2/1 width ratio

Integer values must be at least 1. Width-list values must be positive numbers.


type: string

Minimum width of each column (CSS value).

Examples:

  • "120px"
  • "240px"

type: string

Gap between columns (CSS value).

Examples:

  • "8px"
  • "16px"
  • "32px"

type: string | None

Controls column borders:

  • None — use theme defaults
  • "" — disable borders
  • CSS string — custom border (e.g. "1px solid red")

type: "sidebar" | "inline" | "bottom"

Controls where the columns are rendered.


type: string

Unique identifier used to distinguish widgets with identical arguments.


type: bool

Controls what happens when Mercury reuses the same Columns instance:

  • False — clear previous column content before writing new content (default)
  • True — keep previous content and append new output

  • Columns are responsive and automatically wrap when space is limited.
  • Each returned object is an Output widget with a .clear() method.
  • Use with column: blocks to write content into columns.
  • By default, reruns replace previous column content. Use append=True to accumulate content.
  • Columns are ideal for charts, tables, metrics, or grouped controls.