Mosaic
Mosaic builds linked dashboards from a spec (a dict or YAML) of charts, inputs, and shared selections. Brush one chart and every view that shares the selection redraws, whether the table has a thousand rows or ten million.

2 million synthetic flight records, crossfiltered live by a raster density plot and a histogram. Try the app.
Installation
pip install 'shinywidgets[mosaic_widget]'This pulls in mosaic-widget and duckdb. If import mosaic_widget raises an ImportError, run pip install -U narwhals.
Quick start
A spec is a dict. params declares the shared selection; marks reference it by name and get filtered by it.
# Quick start: a two-plot Mosaic crossfilter dashboard.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny.express import ui
from shinywidgets import render_mosaic_widget
# The Palmer Penguins dataset (Gorman, Williams & Fraser, 2014), via Allison
# Horst's palmerpenguins package.
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["species", "flipper_length_mm", "body_mass_g"])
# Brushing either plot sets the "$brush" selection; every plot that reads
# from "penguins" filtered by "$brush" updates together.
spec = {
"params": {"brush": {"select": "crossfilter"}},
"vconcat": [
{
"plot": [
{
"mark": "dot",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": "flipper_length_mm",
"y": "body_mass_g",
"fill": "species",
"r": 2.5,
},
{"select": "intervalXY", "as": "$brush"},
],
"xDomain": "Fixed",
"yDomain": "Fixed",
"width": 600,
"height": 300,
},
{
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 600,
"height": 150,
},
],
}
ui.page_opts(title="Mosaic quick start", fillable=True)
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"penguins": penguins})
MosaicWidget(spec, data={...}) registers each DataFrame as a table in an in-memory DuckDB connection the widget creates for itself. Drag on either plot: the scatter and the histogram both filter, because both marks’ data reference "$brush".
Overview
A look at what you can build. Click any of them to open the app, with its code, in Shinylive.
Reacting to interaction
Every @render_mosaic_widget output has two accessors, dashboard.params() and dashboard.data(), that turn the dashboard’s current selection into ordinary Shiny reactive state. Call one from any reactive context, the same way you’d call input.my_slider(), and that context re-runs whenever the user brushes.
Stat line and table
The simplest consumer: no other widget library, just @render.text and @render.data_frame fed by one @reactive.calc that reads params() once and shares the resulting relation.
# Linked view: a brush drives a stat line and an aggregated table.
#
# Pairs with: render-widget (plain Shiny outputs, no other widget library
# needed) -- the simplest possible consumer of a Mosaic selection.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny import reactive
from shiny.express import render, ui
from shinywidgets import render_mosaic_widget
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["species", "flipper_length_mm", "body_mass_g"])
spec = {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "dot",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": "flipper_length_mm",
"y": "body_mass_g",
"fill": "species",
"r": 2.5,
},
{"select": "intervalXY", "as": "$brush"},
],
"xDomain": "Fixed",
"yDomain": "Fixed",
"width": 600,
"height": 320,
}
ui.page_opts(title="Linked stats + table", fillable=True)
with ui.layout_columns(col_widths=[7, 5]):
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"penguins": penguins})
with ui.card():
ui.card_header("Selected penguins")
@reactive.calc
def selected():
dashboard.params()
return dashboard.data()
@render.text
def n_selected():
(n,) = selected().aggregate("count(*)").fetchall()[0]
return f"{n} of {len(penguins)} selected"
@render.data_frame
def by_species():
cols = "species, count(*) AS n, round(avg(body_mass_g)) AS mean_mass"
df = selected().aggregate(cols, "species").order("species").df()
return render.DataGrid(df)

Updating in place
A MosaicWidget’s spec is a regular synced trait: assigning .widget.spec = new_spec re-renders the dashboard in the browser without creating a new widget, a new DuckDB connection, or sending another copy of Mosaic’s JavaScript bundle. The tradeoff is that Mosaic rebuilds the whole dashboard from the new spec, so the current selection resets.
# Restyle the dashboard in place by assigning a new `.widget.spec`.
#
# Changing an existing MosaicWidget's `spec` trait re-renders it in the
# browser without creating a new widget, a new DuckDB connection, or sending
# another copy of Mosaic's JavaScript bundle. The tradeoff: Mosaic rebuilds
# the whole dashboard from the new spec, so the current selection resets.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny import reactive
from shiny.express import input, ui
from shinywidgets import render_mosaic_widget
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["flipper_length_mm"])
def make_spec(fill: str) -> dict:
return {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": fill,
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 600,
"height": 260,
}
ui.page_opts(title="Restyle in place", fillable=True)
ui.input_radio_buttons(
"color", "Bar color", choices=["steelblue", "darkorange", "seagreen"]
)
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
# The render function must not depend on input.color(): that would
# rebuild the whole widget on every color change, which is exactly
# what the in-place update below avoids.
with reactive.isolate():
color = input.color()
return MosaicWidget(make_spec(color), data={"penguins": penguins})
@reactive.effect
def _restyle():
color = input.color()
with reactive.isolate():
w = dashboard.widget
if w is not None:
w.spec = make_spec(color)

Restyling really does reset the selection: the brush is present on the left and gone on the right. If your styling change doesn’t need to survive a brush, this is still almost always the right tool – re-rendering the whole output recreates the widget, its DuckDB connection, and reloads the JS bundle.
params itself is a synced trait too, but it’s effectively read-only from Python: setting dashboard.widget.params = {...} updates the Python-side value without filtering anything in the browser. To change what’s selected, send a new spec or wait for the user to brush again.
Linking widgets
Put the two ideas together and one plot can drive another.
Highlight a lonboard map
A Mosaic brush highlights matching points on a lonboard map. The map isn’t re-rendered on every brush move: its layer’s colors are reassigned in place inside a @reactive.effect, wrapped in reactive.isolate() so reading geo_map.widget doesn’t itself create a dependency. That keeps the map’s pan/zoom state untouched and avoids rebuilding its WebGL layer on every update.
# Linked view: a Mosaic brush highlights matching points on a lonboard map.
#
# Pairs with: lonboard. The map isn't re-rendered on every brush move -- its
# layer's colors are updated in place (`reactive.isolate()` + assignment),
# which keeps the map's pan/zoom state untouched.
#
# Synthetic store locations (a small bundled dataset with this lon/lat/revenue
# shape isn't readily available) spread across the continental US.
from __future__ import annotations
import geopandas as gpd
import numpy as np
import pandas as pd
from lonboard import Map, ScatterplotLayer
from mosaic_widget import MosaicWidget
from shiny import reactive
from shiny.express import ui
from shinywidgets import render_lonboard, render_mosaic_widget
rng = np.random.default_rng(3)
n = 1500
stores = pd.DataFrame(
{
"id": np.arange(n),
"lon": rng.uniform(-124, -70, n),
"lat": rng.uniform(26, 48, n),
"revenue": rng.gamma(2.0, 4000, n),
}
)
GDF = gpd.GeoDataFrame(geometry=gpd.points_from_xy(stores.lon, stores.lat), crs="EPSG:4326")
DIM, BRIGHT = (120, 140, 200, 140), (255, 140, 0, 255)
spec = {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "rectY",
"data": {"from": "stores"},
"x": {"bin": "revenue"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 600,
"height": 220,
}
ui.page_opts(title="Mosaic + lonboard", fillable=True)
with ui.layout_columns(col_widths=[6, 6]):
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"stores": stores})
with ui.card(full_screen=True):
@render_lonboard
def geo_map():
colors = np.array([DIM] * n, dtype=np.uint8)
layer = ScatterplotLayer.from_geopandas(
GDF, get_fill_color=colors, radius_units="pixels", get_radius=4
)
return Map(layer)
@reactive.effect
def _highlight():
params = dashboard.params()
active = params.get("brush", {}).get("predicate", "").strip() != ""
if active:
selected_ids = {row[0] for row in dashboard.data().select("id").fetchall()}
colors = np.array(
[BRIGHT if i in selected_ids else DIM for i in stores.id], dtype=np.uint8
)
else:
colors = np.array([DIM] * n, dtype=np.uint8)
with reactive.isolate():
w = geo_map.widget
if w is not None:
w.layers[0].get_fill_color = colors

Guard against the trivial case: params() is {} before any brush, and an unfiltered data() then returns every row, which would otherwise paint the whole map bright on load. Checking the predicate’s truthiness first (as active does here) keeps “nothing selected” and “everything selected” visually distinct.
Feed a plotly chart
Unlike the lonboard pairing, a small plotly figure is cheap enough to just re-render on every brush move – render_plotly only needs a Figure object back, built fresh each time from dashboard.data().
# Linked view: a Mosaic brush feeds a small plotly bar chart.
#
# Pairs with: plotly. Unlike the lonboard example, this chart is cheap enough
# to re-render on every brush move -- `render_plotly` just needs a Figure
# object, built here from `dashboard.data()`.
from __future__ import annotations
import pandas as pd
import plotly.express as px
from mosaic_widget import MosaicWidget
from shiny import reactive
from shiny.express import ui
from shinywidgets import render_mosaic_widget, render_plotly
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["species", "flipper_length_mm"])
spec = {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 500,
"height": 220,
}
ui.page_opts(title="Mosaic + plotly", fillable=True)
with ui.layout_columns(col_widths=[7, 5]):
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"penguins": penguins})
with ui.card(full_screen=True):
@render_plotly
def species_counts():
dashboard.params()
counts = dashboard.data().aggregate("species, count(*) AS n", "species").df()
return px.bar(counts, x="species", y="n", color="species", title="Selected, by species")

Accessor reference
| accessor | returns | before any interaction | across re-render | default rate policy |
|---|---|---|---|---|
params() |
dict[str, Any]: {name: {"value": ..., "predicate": ...}} per active selection |
seeded {} |
re-seeded from the new dashboard | debounce, 250ms |
data(table=None, *, filter_by=None) |
duckdb.DuckDBPyRelation (lazy) |
matches params()’s seed (every row, unfiltered) |
re-seeded, following params() |
inherits params()’s |
Both describe the dashboard’s current selection, not a memory of past brushes – a re-render always re-seeds them from the new dashboard’s own (empty) selection. dashboard.widget.sql is a third, non-reactive way to read the current state: a plain Python property holding the SQL for the dashboard’s current state as a string.
params()
# `dashboard.params()`: read the dashboard's current selection as a Python dict.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny.express import render, ui
from shinywidgets import render_mosaic_widget
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["flipper_length_mm"])
spec = {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 600,
"height": 220,
}
ui.page_opts(title="params() accessor", fillable=True)
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"penguins": penguins})
with ui.card():
ui.card_header("dashboard.params()")
@render.code
def raw_params():
return str(dashboard.params())

predicate is the selection’s clauses already ANDed together and ready to drop into a WHERE clause; value is the latest raw value only (here, the two x bounds of the drag). Before any interaction this is {}, not None, so you can read it immediately with no req() guard.
data()
# `dashboard.data()`: the selected rows as a lazy DuckDB relation.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny import reactive
from shiny.express import render, ui
from shinywidgets import render_mosaic_widget
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["species", "flipper_length_mm", "body_mass_g"])
spec = {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 600,
"height": 220,
}
ui.page_opts(title="data() accessor", fillable=True)
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"penguins": penguins})
# Take the (debounced) params() dependency once, then run one DuckDB query
# and share the result across outputs.
@reactive.calc
def selected():
dashboard.params()
return dashboard.data()
with ui.card():
ui.card_header("Selected rows, aggregated in DuckDB")
@render.code
def summary():
row = selected().aggregate(
"count(*), round(avg(body_mass_g)) AS avg_mass"
).fetchall()[0]
n, avg_mass = row
return f"{n} penguins selected, average body mass {avg_mass} g"

table= can be omitted when the spec’s data entries plus the frames you passed to data= name exactly one table, as here; with more than one source table, pass the one you want (dashboard.data("penguins")), or the widget raises a ValueError naming the options.
By default dashboard.data() filters by every active selection. Pass filter_by= to narrow that to one selection (or a list of them) instead – useful any time a view should reflect only part of what’s selected, for example a value box that keeps tracking a species filter even while the user is also dragging a flipper brush. filter_by="species" and filter_by="$species" are equivalent.
Tuning accessors
Reading on demand
data() is live the instant the dashboard renders, so a download handler can read it the moment the user clicks – no earlier read needed to “arm” it. This also puts filter_by= to work: the dashboard below has two independent selections (a species toggle and a flipper-length brush), and the download exports rows matching only the flipper brush, ignoring whichever species bar is clicked.
# Linked view + read on demand: export rows matching one selection, picked
# with filter_by=, from a two-selection crossfilter dashboard.
#
# Pairs with: quak (same read-on-demand export pattern, there on
# table.data()). The download handler reads dashboard.data() only when the
# user clicks Download -- no warm-up needed, since the accessor is live from
# the moment the dashboard renders.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny import render
from shiny.express import ui
from shinywidgets import render_mosaic_widget
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["species", "flipper_length_mm"])
spec = {
"params": {
"species": {"select": "intersect"},
"flipper": {"select": "intersect"},
},
"hconcat": [
{
"plot": [
{
"mark": "barX",
"data": {"from": "penguins", "filterBy": "$flipper"},
"x": {"count": ""},
"y": "species",
"fill": "steelblue",
"sort": {"y": "-x"},
},
{"select": "toggleY", "as": "$species"},
],
"yLabel": None,
"marginLeft": 90,
"width": 280,
"height": 160,
},
{
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$species"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$flipper"},
],
"xDomain": "Fixed",
"width": 340,
"height": 160,
},
],
}
ui.page_opts(title="Export filtered rows (filter_by=)", fillable=True)
with ui.layout_columns(col_widths=[8, 4]):
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"penguins": penguins})
with ui.card():
ui.card_header("Export")
"Rows matching the flipper-length brush only -- filter_by picks that one selection, ignoring any species clicked above."
@render.download_button(filename="flipper_selected.csv", label="Download CSV")
def download():
yield dashboard.data(filter_by="flipper").df().to_csv(index=False)

The downloaded CSV still has every species in it: filter_by="flipper" picked only the brush, ignoring the species toggle.
Rate limiting
# `rate_delay=0`: see every raw params() update a brush drag sends.
#
# Left: default debounce (250ms) -- the counter settles once after each drag.
# Right: `rate_delay=0` -- the counter climbs during the drag itself, one tick
# per message the browser sends.
from __future__ import annotations
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny import reactive
from shiny.express import render, ui
from shinywidgets import render_mosaic_widget
PENGUINS_URL = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
penguins = pd.read_csv(PENGUINS_URL).dropna(subset=["flipper_length_mm"])
spec = {
"params": {"brush": {"select": "crossfilter"}},
"plot": [
{
"mark": "rectY",
"data": {"from": "penguins", "filterBy": "$brush"},
"x": {"bin": "flipper_length_mm"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
{"select": "intervalX", "as": "$brush"},
],
"xDomain": "Fixed",
"width": 400,
"height": 220,
}
ui.page_opts(title="Rate limiting", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
ui.card_header("Default: debounce 250ms")
@render_mosaic_widget
def debounced():
return MosaicWidget(spec, data={"penguins": penguins})
update_count_debounced = reactive.value(0)
@reactive.effect
def _count_debounced():
debounced.params()
with reactive.isolate():
update_count_debounced.set(update_count_debounced() + 1)
@render.text
def n_debounced():
return f"params() fired {update_count_debounced()} times"
with ui.card(full_screen=True):
ui.card_header("rate_delay=0: every raw update")
@render_mosaic_widget(rate_delay=0)
def live():
return MosaicWidget(spec, data={"penguins": penguins})
update_count_live = reactive.value(0)
@reactive.effect
def _count_live():
live.params()
with reactive.isolate():
update_count_live.set(update_count_live() + 1)
@render.text
def n_live():
return f"params() fired {update_count_live()} times"
The left card settles once per drag (the default, 250ms debounce); the right counts continuously while you’re still dragging (rate_delay=0). Keep the default for anything that triggers a DuckDB aggregate or updates another widget. Pass rate_policy="throttle" to the renderer for updates during the drag without going fully unlimited, and rate_delay=0 only for debugging the raw stream.
Large data
A million-row raster
A raster mark never ships individual points: DuckDB bins every row into a pixel grid server-side and Mosaic draws the result as an image, so render cost and message size are set by plot resolution, not row count. This is the mark to reach for once a dot mark would mean plotting tens of thousands of overlapping points. That’s the “summarize on the server” approach from Large data & performance.
# A density raster over 1 million rows, crossfiltered with a histogram.
#
# Mosaic never ships raw rows to the browser for a `raster` mark: it asks
# DuckDB to pre-aggregate into pixel bins, so the plot renders and rebrushes
# in well under a second regardless of row count.
#
# 1M synthetic rows (a real dataset this large and this shape isn't readily
# available as a small download): carrier-free flight hour/delay pairs.
from __future__ import annotations
import numpy as np
import pandas as pd
from mosaic_widget import MosaicWidget
from shiny.express import ui
from shinywidgets import render_mosaic_widget
rng = np.random.default_rng(0)
n = 1_000_000
hour = rng.uniform(0, 24, n)
delay = rng.gamma(2.0, 8.0, n) - 10 + np.where(hour > 16, (hour - 16) * 2, 0)
flights = pd.DataFrame({"hour": hour, "delay": np.clip(delay, -20, 120)})
spec = {
"params": {"brush": {"select": "crossfilter"}},
"vconcat": [
{
"plot": [
{
"mark": "raster",
"data": {"from": "flights"},
"x": "hour",
"y": "delay",
"fill": "density",
},
{"select": "intervalXY", "as": "$brush"},
],
"xDomain": [0, 24],
"yDomain": [-20, 120],
"colorScale": "symlog",
"colorScheme": "turbo",
"width": 600,
"height": 280,
},
{
"plot": [
{
"mark": "rectY",
"data": {"from": "flights", "filterBy": "$brush"},
"x": {"bin": "hour"},
"y": {"count": ""},
"fill": "steelblue",
"inset": 0.5,
},
],
"xDomain": [0, 24],
"width": 600,
"height": 120,
},
],
}
ui.page_opts(title="Scale: 1M rows", fillable=True)
with ui.card(full_screen=True):
@render_mosaic_widget
def dashboard():
return MosaicWidget(spec, data={"flights": flights})

Dragging a box on the raster filters the histogram down to just the rows inside it, with no perceptible lag.
Every other mark (bar, line, point) ships the query result to the browser instead, because MosaicWidget(spec, data={...}) registers your DataFrame in a DuckDB connection that lives in this Python process, not in the browser’s own WASM DuckDB – on a large dataset, that result can still be a meaningful payload per brush step. See Linking widgets, pattern 7: brushing large data for the full comparison against a datashader/holoviews raster and a raw-point Scattergl anti-pattern.
Layout and sizing
Mosaic plots carry their own pixel width/height in the spec; the output itself still fills its container the way every shinywidgets output does. The two don’t automatically agree: the card is as wide as its column, but the plot inside stays at the size the spec gave it, leaving empty space when the card is bigger. There’s no fill-style auto-sizing for the plots themselves – size them for the column width you expect.
Two things do adapt automatically:
- Narrow columns shrink plots. Observable Plot applies
max-width: 100%, so a 600px-wide plot in a 300px column scales down proportionally, not clipped. Plots never grow past their spec’d size, only shrink. full_screen=Truecards work, and the brush survives. Entering and leaving full screen on a card re-flows the layout without touching the widget.
An explicit height smaller than the plots causes them to overflow visibly below the output (they aren’t clipped) – give explicit heights room for what the spec actually draws.
Gotchas
Security defaults
Mosaic runs SQL that the visitor’s browser sends, in your Python process. render_mosaic_widget restricts it to the dashboard’s data, so a query that tries to read or write server files is refused. Pass allow_unrestricted_connection=True to lift the restriction for a local, single-user app.
The restriction is permanent for that DuckDB connection. If you pass a con= your own code also uses, do its file reads before the first render. The examples here pass data={"t": df}, which gets its own connection.
Nothing limits how expensive a query is, and a slow one blocks the Python process while it runs.
Other gotchas
- With
data={"t": df}, each session’s data stays private. A shared connection is shared across sessions, so two sessions registering different data under the same table name collide. Share a connection only for data that’s the same for every user. - Each re-render keeps its widget’s memory for the life of the process. For anything that changes often, assign a new spec to
.widget.specinstead, as in Updating in place. - Assigning to
dashboard.widget.paramsdoesn’t change the charts. Send a new spec to reset a selection from Python.
In the gallery
Complete apps in the gallery that use Mosaic:
Learn more
- Mosaic documentation – the full spec, mark, and input catalog.
- Mosaic vgplot – a grammar-of-graphics API that compiles to the same spec dicts used here.
- Related guides: jscatter or embedding-atlas for a single large dataset viewed as points, no crossfilter spec needed.
- quak – a DuckDB-backed table without Mosaic’s chart grammar.
- lonboard – the map library paired with Mosaic above.
2 million flights, crossfiltered live
A crossfilter starter to copy
Layer filtered bars over all data
Menu, chart, and table in sync
Combine click and drag selections