Handwritten digits, with the average of your selection

Data exploration
Crossfilter 1,797 handwritten digit images in embedding-atlas, and Python reconstructs the pixel-average image of exactly the digits you selected.

1,797 handwritten digit images (scikit-learn’s bundled digits dataset), PCA-projected to 2D and shown in embedding-atlas, each with its own image thumbnail. Lassoing a cluster, or clicking a bar in the “digit” histogram to crossfilter, narrows atlas.selected_rows() to exactly those rows – and the sidebar reconstructs the average image of exactly the selected digits, live, from the raw 8x8 pixel arrays. It’s a concrete payoff for “Python computes on what the user circled”: select mostly-3s, and the average image clearly looks like a blurry 3.

Run it

git clone --depth 1 https://github.com/posit-dev/py-shinywidgets
cd py-shinywidgets/website/gallery/showcases/digits-atlas
uv run --with scikit-learn shiny run app.py

Source: app.py · Open in Shinylive

Try this

  • Click a bar in the digit histogram (e.g. “3”): the embedding, the image grid, and the average digit picture all narrow to just that digit – and the averaged image visibly resembles the chosen digit.
  • Lasso a cluster directly on the embedding (works in any WebGPU-capable browser): same effect, driven by the same selected_rows() accessor.
  • Watch the digit breakdown line: it’s computed server-side from the exact same selection, every time.

Accessors demonstrated

  • atlas.selected_rows() – the currently-selected rows as a DataFrame slice (with a __row_index__ column pointing back into the original data), fired by either a canvas lasso or a histogram/table crossfilter click – the same accessor serves both gesture families, which is why this showcase works even without a WebGPU-capable browser for the lasso itself.