quak
quak is a data table built on DuckDB and Mosaic: every column header carries a histogram, and dragging across one crossfilters the whole table. Your DataFrame never leaves Python, so a table of 5 million rows renders about as fast as one of 5 thousand. @render_quak accepts a pandas or polars DataFrame, a pyarrow Table, a DuckDB relation or connection, or a quak.Widget you built yourself, and two accessors, table.sql() and table.data(), read back the current sort and filter.

3 million synthetic rides, crossfiltered live. Try the app.
Installation
pip install 'shinywidgets[quak]'This installs quak and its dependencies (duckdb, pyarrow, anywidget).
Quick start
Return any DataFrame and you get a full table: per-column histograms, sorting, and crossfiltering, with no other code.
from __future__ import annotations
import plotly.express as px
from shiny.express import ui
from shinywidgets import render_quak
ui.page_opts(title="quak quickstart", fillable=True)
gapminder = px.data.gapminder()
with ui.card(full_screen=True):
@render_quak
def table():
return gapminder
Overview
A look at what you can build. Click any of them to open the app, with its code, in Shinylive.
3 million rides, crossfiltered live
5 million rows, roughly constant cost
A DuckDB relation, no DataFrame copy
Read the query behind the view
Live summary stats from filtered rows
Resize without losing the filter
Filtered rows drive a plotly chart
Download exactly what’s on screen
A table plus a live query, to adapt
Fill the card, or a fixed height
Table features
Crossfiltering, free
Drag across a numeric column’s histogram, or click a bar in a categorical column’s histogram, and quak filters the table to the matching rows – every other column’s histogram redraws over the selection (the pale bars are the full data; the dark overlay is the current selection), and a Reset link appears in the status bar. This is the same app as the quick start; the behavior is built into quak itself.


Sorting is also free: hover a column header and three sort states cycle through its sort button (ascending, descending, unsorted).
A DuckDB relation or connection
Besides pandas/polars DataFrames and pyarrow Tables, render_quak accepts a DuckDB relation or connection directly – useful when your data already lives in DuckDB and you don’t want to materialize a DataFrame copy of it first.
from __future__ import annotations
import duckdb
import plotly.express as px
from shiny.express import ui
from shinywidgets import render_quak
ui.page_opts(title="quak from a DuckDB relation", fillable=True)
# Register once; render_quak() also accepts pandas/polars DataFrames and
# pyarrow Tables directly, with no conversion step. DuckDBPyConnection.register()
# returns the connection (for chaining) -- discard it, or Shiny Express's
# auto-display will try to render that return value as page content.
con = duckdb.connect(":memory:")
_ = con.register("gapminder", px.data.gapminder())
by_country_year = con.sql("""
select country, continent, year, lifeExp, pop, gdpPercap
from gapminder
where pop > 2_000_000
""")
with ui.card(full_screen=True):
@render_quak
def table():
return by_country_year
If you pass a bare duckdb.DuckDBPyConnection instead of a relation, quak queries a table named df on it by default – construct quak.Widget(con, table="your_table") yourself if your table has a different name.
Roughly constant cost at scale
Because quak only ever sends the rows on screen and each histogram’s bin counts over the wire, a table of 5 million rows renders about as fast as one of 5 thousand – the cost moved to DuckDB running in your Python process, which is built for exactly this.
from __future__ import annotations
import numpy as np
import pandas as pd
from shiny.express import ui
from shinywidgets import render_quak
ui.page_opts(title="quak at scale", fillable=True)
# Synthetic "ride" data, sized for scale rather than realism: quak only ever
# sends the rows on screen and each histogram's bin counts over the wire, so
# the browser payload is about the same at 5k rows or 5M.
n = 5_000_000
rng = np.random.default_rng(0)
rides = pd.DataFrame(
{
"borough": rng.choice(
["Manhattan", "Brooklyn", "Queens", "Bronx", "Staten Island"],
n,
p=[0.45, 0.25, 0.2, 0.07, 0.03],
),
"hour": rng.integers(0, 24, n),
"trip_minutes": np.clip(rng.gamma(2.0, 6.0, n), 1, 120).round(1),
"fare_usd": np.clip(rng.gamma(3.0, 5.0, n), 2.5, 200).round(2),
}
)
with ui.card(full_screen=True):
ui.card_header(f"{n:,} synthetic rides")
@render_quak
def table():
return rides
Reacting to interaction
Every @render_quak output has table.sql() and table.data(), called from any reactive context the same way you’d call input.my_slider().
Read the query behind the view
table.sql() is the exact SELECT statement for the table’s current sort and filter – read it to show users what’s currently selected, or to replay the same filter against a different query.
from __future__ import annotations
import plotly.express as px
from shiny.express import render, ui
from shinywidgets import render_quak
ui.page_opts(title="quak sql() accessor", fillable=True)
ui.tags.style("pre { white-space: pre-wrap; overflow-wrap: anywhere; }")
gapminder = px.data.gapminder()
with ui.layout_columns(col_widths=[8, 4]):
with ui.card(full_screen=True):
@render_quak
def table():
return gapminder
with ui.card():
ui.card_header("table.sql()")
@render.code
def sql():
# No req() needed: this cancels on its own while quak's query is
# still the empty string it syncs during initialization.
return table.sql()Sorting by life expectancy, then brushing a range of the lifeExp histogram, updates the published query with an ORDER BY and a WHERE ... BETWEEN ...:


Live summary stats
table.data() runs the published query and hands back a lazy duckdb.DuckDBPyRelation – call .df()/.pl() to materialize it, or .aggregate(...) to compute a summary without pulling every row into Python. It takes a dependency on sql(), so it re-runs on the same schedule.
from __future__ import annotations
import plotly.express as px
from shiny.express import render, ui
from shinywidgets import render_quak
ui.page_opts(title="quak data() accessor", fillable=True)
gapminder = px.data.gapminder()
with ui.layout_columns(col_widths=[8, 4]):
with ui.card(full_screen=True):
@render_quak
def table():
return gapminder
with ui.layout_columns(col_widths=12):
with ui.value_box():
"Countries x years selected"
@render.text
def n_rows():
return f"{table.data().aggregate('count(*)').fetchall()[0][0]:,}"
with ui.value_box():
"Median life expectancy"
@render.text
def median_life_exp():
value = table.data().aggregate("median(lifeExp)").fetchall()[0][0]
return f"{value:.1f} years"

Notice the value box can read a different selected-row count than quak’s own status bar reports for the same brush. That’s not a bug in this example – quak’s status-bar count can disagree with the exact row count of its own published query. Treat table.data(), not the status bar text, as the source of truth.
Updating in place
quak’s sql trait is read-only: setting table.widget.sql = "..." from Python changes nothing in the browser. The only thing worth mutating in place is layout – typically .layout.height, inherited from ipywidgets. Doing that on the already-rendered widget keeps the same quak instance, and so keeps whatever filter or sort the user had in progress; re-running the @render_quak function instead always builds a fresh quak.Widget, which loses it (quak has no way to hand a filter back in on construction).
from __future__ import annotations
import plotly.express as px
import quak
from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_quak
ui.page_opts(title="quak: resize in place vs. re-render")
gapminder = px.data.gapminder()
ui.input_action_button("grow", "Grow the table (in place)")
ui.input_action_button("rerender", "Re-render the table")
@render.code
def sql():
return table.sql()
with ui.card():
# A roomy fixed height on the output itself, so toggling the widget's own
# (smaller) layout.height below is never clipped by the output container.
@render_quak(height="700px")
def table():
# Brush or sort, then click "Re-render": this function re-runs and
# builds a brand-new quak.Widget, so the filter/sort is gone -- quak
# has no way to hand a filter back in on construction.
input.rerender()
widget = quak.Widget(gapminder)
widget.layout.height = "250px"
return widget
@reactive.effect
@reactive.event(input.grow)
def _():
# Mutating the already-rendered widget keeps the same quak instance, and
# so keeps whatever the user had brushed or sorted, unlike re-rendering.
current = table.widget.layout.height
table.widget.layout.height = "650px" if current != "650px" else "250px"Brush a filter, then click “Grow the table”: the table grows from 250px to 650px and the filter, visible in the query text, is untouched.


One sizing note this example relies on: when an output fills its container (the default, and what every other example in this guide uses), that fill behavior wins over a manually-set layout.height – the table stretches to the container regardless. Give the output an explicit, roomy height= (as above) when you want layout.height itself to be the thing that visibly changes.
Linking widgets
Filtered rows drive a chart
A chart in a neighboring card, built from table.data().df(), always matches what the table shows – useful when a user wants a different view (here, a distribution) of the same selection, not just a row count.
from __future__ import annotations
import plotly.express as px
from shiny.express import render, ui
from shinywidgets import render_plotly, render_quak
ui.page_opts(title="quak filter -> plotly chart", fillable=True)
gapminder = px.data.gapminder()
with ui.layout_columns(col_widths=[7, 5]):
with ui.card(full_screen=True):
ui.card_header("Brush a histogram or click a continent bar")
@render_quak
def table():
return gapminder
with ui.card(full_screen=True):
ui.card_header("Life expectancy by continent, filtered rows only")
@render_plotly
def chart():
# Re-runs (debounced) whenever table.sql() changes, so the bars
# always describe exactly the rows quak is showing.
filtered = table.data().df()
return px.box(filtered, x="continent", y="lifeExp", color="continent")Clicking the “Europe” bar in the continent column filters the table to European country-years, and the box plot redraws from exactly those rows:


Accessor reference
| Accessor | Returns | Before any interaction | Across a re-render | Default rate policy |
|---|---|---|---|---|
sql() |
str |
cancels (like an unrendered output) during the brief window before the table’s first report | re-seeded from the new table | debounce, 250 ms |
data() |
duckdb.DuckDBPyRelation (lazy) |
cancels alongside sql() |
re-seeded, following sql() |
inherits sql()’s |
Both describe the table’s current state, not a memory of past interaction: a re-render always starts them over from the new table’s own query, so there’s no stale value to worry about carrying across renders. Neither can be read inside the @render_quak function itself, which builds a brand-new table on every call.
sql()
The exact SELECT behind the table’s current sort and filter – see Read the query behind the view above.
data()
A lazy duckdb.DuckDBPyRelation for the same rows, re-run whenever sql() changes – see Live summary stats and Linking widgets above.
Tuning accessors
Reading on demand
An accessor records from the moment the table renders, whether or not anything has read it yet – see Reacting to widgets: Read on demand for the general pattern. table.data() powers an export just as easily as a chart: the download handler below reads it only when the user clicks Download, with nothing lost from an earlier filter, and the result always matches what’s on screen, not the full dataset:
from __future__ import annotations
import plotly.express as px
from shiny import render
from shiny.express import ui
from shinywidgets import render_quak
ui.page_opts(title="quak filter -> CSV download", fillable=True)
gapminder = px.data.gapminder()
with ui.layout_columns(col_widths=[9, 3]):
with ui.card(full_screen=True):
@render_quak
def table():
return gapminder
with ui.card():
ui.card_header("Export")
"Download exactly the rows currently shown (after sorting/filtering)."
@render.download_button(filename="gapminder_filtered.csv", label="Download CSV")
def download():
# table.data() cancels (like an unrendered output) while quak's
# query is still settling, so the button is simply unusable until
# a query exists -- no error handling needed here.
yield table.data().df().to_csv(index=False)
Rate limiting
A brush drag can fire quak’s sql trait many times before the mouse comes up, and each change to table.sql() potentially re-runs a DuckDB query in table.data(). The accessors debounce at 250 ms by default to collapse that into one update per settled gesture, enough for almost every use. Pass rate_policy="throttle" to render_quak (and/or a smaller rate_delay) if you need periodic snapshots while the user is still dragging, for example to drive a progress indicator; pass rate_delay=0 to disable rate limiting entirely and see every raw update, useful for debugging but not production, since some raw updates carry an incomplete query mid-gesture.
.read()
quak’s only other traits aren’t meant to be read from outside the widget – sql() and data() already cover the table’s entire interactive surface. If a future quak release adds a public trait worth watching, table.read("that_trait") reads it reactively, preferred over calling reactive_read(table.widget, "trait") directly.
Large data
quak’s whole premise is this: your DataFrame never leaves Python. It’s registered in a DuckDB connection quak queries directly, sending only the rows on screen and the per-column histogram bin counts – not the underlying table. Roughly constant cost at scale above renders and crossfilters a 5-million-row table at the same cost as 5 thousand. This is the “only send what’s visible” approach from Large data & performance.
Layout and sizing
render_quak fills its container by default, same as every other @render_* output – put it in a ui.card(full_screen=True) inside a fillable page and it grows and shrinks with the card. Pass an explicit height= (to render_quak or output_widget) to opt out and get a fixed size instead.
from __future__ import annotations
import plotly.express as px
from shiny.express import ui
from shinywidgets import render_quak
ui.page_opts(title="quak layout and sizing", fillable=True)
gapminder = px.data.gapminder()
with ui.layout_columns(col_widths=[6, 6]):
with ui.card(full_screen=True):
ui.card_header("Fills its card (default)")
@render_quak
def fills():
return gapminder
with ui.card():
ui.card_header('height="250px"')
@render_quak(height="250px")
def fixed():
return gapminder
Scrolling to load more rows works at any height, however tall the filling container is.
Gotchas
Security
quak runs SQL that the visitor’s browser sends, in your Python process. render_quak turns off the DuckDB connection’s access to server files, so a query like select * from read_csv('/etc/hosts') is refused, and the examples in this guide are safe to deploy as they are. For a local, single-user app, pass allow_unrestricted_connection=True to leave the connection as it is:
from __future__ import annotations
import plotly.express as px
from shiny.express import ui
from shinywidgets import render_quak
ui.page_opts(title="quak with an unrestricted connection (local use only)", fillable=True)
gapminder = px.data.gapminder()
with ui.card(full_screen=True):
@render_quak(allow_unrestricted_connection=True)
def table():
# render_quak() locks down the table's DuckDB connection by default
# (see Gotchas): a visitor's browser can query the data but can't
# read server files or change the connection's settings. Opting out
# here leaves the connection exactly as quak builds it -- only do
# this for a local, single-user app, never one you deploy.
return gapminderThe restriction is permanent for that DuckDB connection. If you pass quak.Widget(con) with a connection your own code also uses, do its file reads (read_parquet(), etc.) before the first render. Every table on that connection stays queryable from the browser, so don’t pass one that holds data visitors shouldn’t see.
A connection you’ve already locked yourself (SET lock_configuration = true) is left as it is, with a warning if it can still read files.
Nothing limits how expensive a query is, and a slow one blocks the Python process while it runs.
Other gotchas
sqlis read-only and briefly empty at startup. Settingtable.widget.sql = ...from Python has no effect; use the accessor to read, and change what’s displayed by re-rendering.- A
timedelta/duration column or a very largeint64column can crash the table, upstream. Cast durations to seconds and oversized integers to strings or floats before rendering. - A bare
duckdb.DuckDBPyConnectionqueries a table nameddfby default. Passing a connection whose data lives under a different table name renders a blank table instead; constructquak.Widget(con, table="your_table_name")yourself if your table has a different name. - A
layout.heightset from Python has no effect while the output fills its container; give the output a fixedheight=to resize it from Python, as in Updating in place.
Learn more
- quak on GitHub
- Mosaic
- Related guides: mosaic, perspective, itables, reactable, ipydatagrid