diff --git a/assets/css/main.css b/assets/css/main.css index 2b48cf211..bdff64786 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -362,6 +362,27 @@ html { .code-with-filename .code-with-filename-label { background-color: var(--color-blue-200); padding: 0.4rem 1.1428571em; + display: flex; + align-items: center; + gap: 1rem; +} + +.prose .code-shinylive-link { + margin-left: auto; + display: inline-flex; + align-items: center; + gap: 0.35rem; + font-size: 0.875rem; + font-weight: 500; + text-decoration: none; +} + +.prose .code-shinylive-link:hover { + text-decoration: underline; +} + +.code-shinylive-link svg { + fill: currentColor; } .code-with-filename div.highlight, diff --git a/content/blog/CLAUDE.md b/content/blog/CLAUDE.md index e66deed6f..4824fc20b 100644 --- a/content/blog/CLAUDE.md +++ b/content/blog/CLAUDE.md @@ -22,6 +22,7 @@ Every post must have: | `description` | 1-2 sentences; shown in card listings, under the post hero, and in social previews | | `image` | Thumbnail/hero image filename; 1920×1080 PNG or JPG recommended (16:9); GIF is supported and animation will play | | `image-alt` | Alt text for the image — describe what it shows, not just "screenshot" | +| `image-video` | Optional hero video filename (mp4). On the post page the hero plays it as a muted loop with `image` as the poster; `image` is still what the listing card and social previews show | | `topics` | Fixed set — see below | | `software` | Projects the post is about; use folder names from `content/software/` | | `languages` | Programming languages (R, Python, etc.) | diff --git a/content/blog/shinywidgets-1-0/_feature-src/capture.py b/content/blog/shinywidgets-1-0/_feature-src/capture.py new file mode 100644 index 000000000..9879dc17f --- /dev/null +++ b/content/blog/shinywidgets-1-0/_feature-src/capture.py @@ -0,0 +1,43 @@ +"""Regenerate the post's featured image from feature.html. + +Writes featured.jpg (1920x1080) to the post directory (the parent of this +folder). The screenshot tiles in img/ come from the shinywidgets website's +landing page and the gallery apps. + +Usage: + + uv run --with playwright python capture.py +""" + +import pathlib + +from playwright.sync_api import sync_playwright + +HERE = pathlib.Path(__file__).parent +POST_DIR = HERE.parent +SRC = (HERE / "feature.html").as_uri() + +WIDTH, HEIGHT = 1200, 675 # 16:9; 1.6x device scale gives 1920x1080 + +with sync_playwright() as p: + browser = p.chromium.launch() + page = browser.new_page( + viewport={"width": WIDTH, "height": HEIGHT}, + device_scale_factor=1.6, + ) + page.goto(SRC) + # Fail loudly if the site fonts or tiles did not load; fallbacks look wrong. + page.evaluate("() => document.fonts.ready") + for spec in ('700 16px "Open Sans"', '500 16px "Source Code Pro"'): + if not page.evaluate(f"() => document.fonts.check('{spec}')"): + raise SystemExit(f"font not loaded: {spec}") + broken = page.evaluate( + "[...document.images].filter(i => !i.naturalWidth).map(i => i.src)" + ) + if broken: + raise SystemExit(f"images not loaded: {broken}") + page.wait_for_timeout(300) + page.screenshot(path=str(POST_DIR / "featured.jpg"), type="jpeg", quality=85) + browser.close() + +print("featured.jpg written (1920x1080)") diff --git a/content/blog/shinywidgets-1-0/_feature-src/capture_gallery_hover.py b/content/blog/shinywidgets-1-0/_feature-src/capture_gallery_hover.py new file mode 100644 index 000000000..37d5a0ef7 --- /dev/null +++ b/content/blog/shinywidgets-1-0/_feature-src/capture_gallery_hover.py @@ -0,0 +1,138 @@ +"""Record the gallery "stage" on the shinywidgets.org landing page. + +The stage auto-plays each of the six featured apps (a ~7s gesture animation, +then it advances). This script drives it deterministically: a scripted cursor +glides onto each app in the picker list, a JS click restarts that app's +animation just as the cursor arrives, and it plays start-to-finish before the +cursor moves on. Clicks are timed ~100ms before autoplay would advance so the +auto-advance never fires mid-recording. + +Playwright's video doesn't render an OS cursor, so we inject an SVG cursor +that follows the (scripted) mouse via mousemove events. + +Usage: + + uv run --with playwright python capture_gallery_hover.py + +Writes gallery-hover.mp4 next to this script (2320x1182 h264). Playwright's +video captures at CSS-pixel size even with a device scale factor, so for a +hi-res recording we zoom the page 2x inside a 2560x1600 viewport and crop to +the stage. The injected cursor lives outside the zoomed body (mouse events +report viewport coordinates regardless of zoom) and is drawn 2x to match. +""" + +import pathlib +import subprocess +import tempfile +import time + +from playwright.sync_api import sync_playwright + +HERE = pathlib.Path(__file__).parent +OUT = HERE.parent / "gallery-hover.mp4" +URL = "https://shinywidgets.org/" + +WIDTH, HEIGHT = 2560, 1600 +ZOOM = 2 +# landing.js: each showcase plays for DUR ms, then autoplay advances. +DUR_MS = 7000 +# Click the next app this long after the previous click: the full gesture +# (done by 5600ms) plus most of the progress bar, but before autoplay fires. +ITEM_MS = DUR_MS - 100 +N_ITEMS = 6 + +CURSOR_JS = """ +() => { + const c = document.createElement('div'); + c.style.cssText = 'position:fixed;z-index:999999;pointer-events:none;left:0;top:0;margin:0'; + c.innerHTML = ` + + `; + document.documentElement.appendChild(c); + addEventListener('mousemove', e => { + c.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`; + }); +} +""" + +PRELOAD_JS = """ +async () => { + const imgs = SHOWCASES.flatMap(s => [0, 1].map(i => { + const img = new Image(); + img.src = `assets/landing/img/show-${s.id}-${i}.webp`; + return img.decode().catch(() => {}); + })); + await Promise.all(imgs); + return SHOWCASES.map(s => s.id); +} +""" + + +def main() -> None: + with sync_playwright() as p, tempfile.TemporaryDirectory() as vdir: + browser = p.chromium.launch() + context = browser.new_context( + viewport={"width": WIDTH, "height": HEIGHT}, + record_video_dir=vdir, + record_video_size={"width": WIDTH, "height": HEIGHT}, + ) + page = context.new_page() + t0 = time.monotonic() # video starts recording with the page + page.goto(URL, wait_until="networkidle") + page.evaluate(f"() => {{ document.body.style.zoom = {ZOOM} }}") + ids = page.evaluate(PRELOAD_JS) + assert len(ids) == N_ITEMS, ids + page.evaluate(CURSOR_JS) + + # Frame just the stage (the app picker + animated browser, not the + # section title/subtitle); scrolling it into view starts the autoplay. + page.evaluate( + "() => scrollTo(0, document.getElementById('stage')" + ".getBoundingClientRect().top + scrollY - 12)" + ) + page.wait_for_timeout(800) + # trim the pre-scroll page top off the head of the video, keeping a + # short lead-in before the cursor starts moving + head = max(0.0, time.monotonic() - t0 - 0.3) + stage_box = page.locator("#stage").bounding_box() + # h264/yuv420p needs even dimensions + crop = [ + 2 * int(stage_box["x"] // 2), + 2 * int(stage_box["y"] // 2), + 2 * int(stage_box["width"] // 2), + 2 * int(stage_box["height"] // 2), + ] + + items = page.locator("#picker li") + centers = [] + for i in range(N_ITEMS): + box = items.nth(i).bounding_box() + centers.append((box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)) + + # Park the cursor above the first item, then glide in. + page.mouse.move(centers[0][0], centers[0][1] - 140 * ZOOM) + for i, (x, y) in enumerate(centers): + page.mouse.move(x, y, steps=25) # ~GLIDE_MS of mousemove events + items.nth(i).evaluate("(el) => el.click()") + # Don't outwait the last item's DUR or autoplay loops to item 0 + page.wait_for_timeout(ITEM_MS if i < N_ITEMS - 1 else DUR_MS - 400) + + context.close() # finalizes the .webm + browser.close() + + webm = next(pathlib.Path(vdir).glob("*.webm")) + subprocess.run( + [ + "ffmpeg", "-y", "-ss", f"{head:.2f}", "-i", str(webm), + "-vf", f"crop={crop[2]}:{crop[3]}:{crop[0]}:{crop[1]}", + "-an", "-c:v", "libx264", "-pix_fmt", "yuv420p", + "-crf", "21", "-preset", "slow", "-movflags", "+faststart", + str(OUT), + ], + check=True, + ) + print(f"wrote {OUT}") + + +if __name__ == "__main__": + main() diff --git a/content/blog/shinywidgets-1-0/_feature-src/capture_video.py b/content/blog/shinywidgets-1-0/_feature-src/capture_video.py new file mode 100644 index 000000000..54709b4f7 --- /dev/null +++ b/content/blog/shinywidgets-1-0/_feature-src/capture_video.py @@ -0,0 +1,86 @@ +"""Record an animated version of feature.html for the post's hero video. + +Writes PNG frames to /tmp/feature-frames/ at 2400x1350 (1200x675 @ 2x), then +prints the ffmpeg command to encode featured.mp4 with a seamless-loop +crossfade. The static featured.jpg comes from capture.py; this script injects +the tile drift at runtime so feature.html itself stays static. + +Playwright's video recording caps at 800px and resizes the window in ways that +break this fixed-size card, so instead we seek the CSS animations to +deterministic timestamps and screenshot each frame. + +Usage: + + uv run --with playwright python capture_video.py +""" + +import pathlib + +from playwright.sync_api import sync_playwright + +HERE = pathlib.Path(__file__).parent +SRC = (HERE / "feature.html").as_uri() +FRAMES = pathlib.Path("/tmp/feature-frames") + +WIDTH, HEIGHT = 1200, 675 +FPS = 24 +# All columns share one drift period (phase-shifted for variety), so capturing +# exactly one period gives a pixel-perfect loop with no crossfade. 40s at +# 830px/period is a slow ~21px/s drift. +SECONDS = 40 # must equal the animation period passed to the page +OFFSET_MS = 0 +# One set of 5 tiles + 5 gaps in feature.html's .col (5*150 + 5*16) +DRIFT_PX = 830 + +FRAMES.mkdir(exist_ok=True) + +with sync_playwright() as p: + browser = p.chromium.launch() + page = browser.new_page( + viewport={"width": WIDTH, "height": HEIGHT}, + device_scale_factor=2, + ) + page.goto(SRC) + page.evaluate("() => document.fonts.ready") + broken = page.evaluate( + "[...document.images].filter(i => !i.naturalWidth).map(i => i.src)" + ) + if broken: + raise SystemExit(f"images not loaded: {broken}") + + page.evaluate( + """([driftPx, periodSeconds]) => { + const style = document.createElement('style'); + style.textContent = `@keyframes sw-drift { + from { transform: translateY(0); } + to { transform: translateY(-${driftPx}px); } + }`; + document.head.appendChild(style); + document.querySelectorAll('.wall .col').forEach((col, i) => { + col.innerHTML += col.innerHTML; // repeat the set so the drift loops + col.style.animation = `sw-drift ${periodSeconds}s linear infinite`; + col.style.animationDelay = `-${(periodSeconds * i) / 3}s`; + if (i === 1) col.style.animationDirection = 'reverse'; + }); + document.getAnimations().forEach(a => a.pause()); + }""", + [DRIFT_PX, SECONDS], + ) + + total = FPS * SECONDS + for i in range(total): + page.evaluate( + "(t) => document.getAnimations().forEach(a => { a.currentTime = t })", + OFFSET_MS + i * 1000 // FPS, + ) + page.screenshot(path=str(FRAMES / f"{i:04d}.png")) + if (i + 1) % 100 == 0: + print(f"{i + 1}/{total}") + browser.close() + +print(f"frames in {FRAMES}") +# 1280px is plenty for the hero banner (at most 384px tall, cropped), and keeps +# the 40s loop near 2 MB instead of ~7 MB at 1920px. +print("encode: ffmpeg -y -framerate 24 -i /tmp/feature-frames/%04d.png " + "-vf scale=1280:720:flags=lanczos -an -c:v libx264 -pix_fmt yuv420p " + "-crf 28 -preset slow -movflags +faststart featured.mp4") diff --git a/content/blog/shinywidgets-1-0/_feature-src/feature.html b/content/blog/shinywidgets-1-0/_feature-src/feature.html new file mode 100644 index 000000000..d3b691306 --- /dev/null +++ b/content/blog/shinywidgets-1-0/_feature-src/feature.html @@ -0,0 +1,166 @@ + + + + + + + + +
+
+ +
+
New release
+

shinywidgets 1.0

+
Bring your Jupyter widgets
to Shiny.
+
+ 40+ widget libraries + Reactive accessors + New docs & gallery + Production-ready + Agent skill + & more… +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/brain.webp b/content/blog/shinywidgets-1-0/_feature-src/img/brain.webp new file mode 100644 index 000000000..256dcdba4 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/brain.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/cells.webp b/content/blog/shinywidgets-1-0/_feature-src/img/cells.webp new file mode 100644 index 000000000..db5cfc1e6 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/cells.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/chat.webp b/content/blog/shinywidgets-1-0/_feature-src/img/chat.webp new file mode 100644 index 000000000..7df33165a Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/chat.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/counties.webp b/content/blog/shinywidgets-1-0/_feature-src/img/counties.webp new file mode 100644 index 000000000..4e522356e Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/counties.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/issues.webp b/content/blog/shinywidgets-1-0/_feature-src/img/issues.webp new file mode 100644 index 000000000..7d02b1e89 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/issues.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/stars3d.webp b/content/blog/shinywidgets-1-0/_feature-src/img/stars3d.webp new file mode 100644 index 000000000..66758d72f Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/stars3d.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/starshr.webp b/content/blog/shinywidgets-1-0/_feature-src/img/starshr.webp new file mode 100644 index 000000000..2b953f0b1 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/starshr.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/terrain.webp b/content/blog/shinywidgets-1-0/_feature-src/img/terrain.webp new file mode 100644 index 000000000..e2699b8dc Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/terrain.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/trade.webp b/content/blog/shinywidgets-1-0/_feature-src/img/trade.webp new file mode 100644 index 000000000..d9a670c82 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/trade.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/wall-datashader.webp b/content/blog/shinywidgets-1-0/_feature-src/img/wall-datashader.webp new file mode 100644 index 000000000..66286fc5f Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/wall-datashader.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/wall-maplibre.webp b/content/blog/shinywidgets-1-0/_feature-src/img/wall-maplibre.webp new file mode 100644 index 000000000..fa05eedf3 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/wall-maplibre.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/wall-mols2grid.webp b/content/blog/shinywidgets-1-0/_feature-src/img/wall-mols2grid.webp new file mode 100644 index 000000000..0c234ca74 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/wall-mols2grid.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/wall-nglview.webp b/content/blog/shinywidgets-1-0/_feature-src/img/wall-nglview.webp new file mode 100644 index 000000000..45a4c2d3a Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/wall-nglview.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/whales-us.webp b/content/blog/shinywidgets-1-0/_feature-src/img/whales-us.webp new file mode 100644 index 000000000..35536b681 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/whales-us.webp differ diff --git a/content/blog/shinywidgets-1-0/_feature-src/img/world.webp b/content/blog/shinywidgets-1-0/_feature-src/img/world.webp new file mode 100644 index 000000000..5ee2ee7d8 Binary files /dev/null and b/content/blog/shinywidgets-1-0/_feature-src/img/world.webp differ diff --git a/content/blog/shinywidgets-1-0/categories.png b/content/blog/shinywidgets-1-0/categories.png new file mode 100644 index 000000000..f8fbd1597 Binary files /dev/null and b/content/blog/shinywidgets-1-0/categories.png differ diff --git a/content/blog/shinywidgets-1-0/chat-selection.webp b/content/blog/shinywidgets-1-0/chat-selection.webp new file mode 100644 index 000000000..a4e545503 Binary files /dev/null and b/content/blog/shinywidgets-1-0/chat-selection.webp differ diff --git a/content/blog/shinywidgets-1-0/featured.jpg b/content/blog/shinywidgets-1-0/featured.jpg new file mode 100644 index 000000000..7c232c09f Binary files /dev/null and b/content/blog/shinywidgets-1-0/featured.jpg differ diff --git a/content/blog/shinywidgets-1-0/featured.mp4 b/content/blog/shinywidgets-1-0/featured.mp4 new file mode 100644 index 000000000..ec8763e4a Binary files /dev/null and b/content/blog/shinywidgets-1-0/featured.mp4 differ diff --git a/content/blog/shinywidgets-1-0/index.md b/content/blog/shinywidgets-1-0/index.md new file mode 100644 index 000000000..42c21cd90 --- /dev/null +++ b/content/blog/shinywidgets-1-0/index.md @@ -0,0 +1,306 @@ +--- +title: 'shinywidgets 1.0: bring your Jupyter widgets to Shiny' +date: 2026-12-08T00:00:00.000Z +people: + - Carson Sievert + - Shiny Team +description: > + shinywidgets 1.0 brings dedicated support for 40+ interactive Python libraries + to Shiny, plus a new website and a simpler way to react to clicks, selections, + and other user interactions. +image: featured.jpg +image-video: featured.mp4 +image-alt: > + The words "shinywidgets 1.0: Bring your Jupyter widgets to Shiny" beside a + wall of widget screenshots, including a map of US counties, a protein + structure, ship tracks, a brain scan, 3D terrain, and a molecule grid. +topics: + - Interactive Apps + - Visualization +software: + - py-shinywidgets + - shiny-python +languages: + - Python +source: shiny +hidesubscription: false +--- + + +I'm excited to announce that [shinywidgets 1.0](https://pypi.org/project/shinywidgets/) is now on PyPI! Grab it now with: + +``` bash +pip install -U shinywidgets +``` + +In principle, shinywidgets lets you use any Jupyter widget library (plotly, altair, and so on) in [Shiny](https://shiny.posit.co/py/). +In practice, most widgets are written for one person's notebook, and many need workarounds before they reliably load, size, re-render, and scale to many concurrent users. +In 1.0, dozens of libraries get those workarounds built in, and the failure modes they had in common led to fixes in the logic every widget shares. + +Integrations are the bulk of this release, but not all of it. Here are the highlights: + +- [Support for 40+ libraries](#40-integrations), documented on a [new website](#a-new-website) and in an [agent skill](#for-your-coding-agent). +- [Reactive accessors](#reactive-accessors) that turn common interactions, from a click to a map pan, into reactive values. +- [Many fixes and improvements](#many-improvements), especially for widgets in deployed, multi-user apps. + +If you're upgrading an existing app, see [Upgrading](#upgrading) for the few things to check. + +## A new website + +[shinywidgets.org](https://shinywidgets.org) has a guide for every supported library, a gallery of complete apps, and longer guides on everything from choosing a widget to keeping an app fast. + +The shinywidgets.org homepage, with the headline 'Bring your Jupyter widgets to Shiny' over a tiled wall of widget app screenshots, and buttons to get started or browse the gallery. + +### 40+ integrations + +Before 1.0, only three libraries had their own decorator. +Everything else went through the generic `@render_widget`, and often needed extra work to look and behave right. +Now 40+ libraries each get their own decorator (e.g., `@render_geolibre`), an install extra (e.g., `pip install 'shinywidgets[geolibre]'`), sizing that fits Shiny's layouts, and a guide with runnable examples. +The table below groups them by what you're building, and each name links to its guide. + +Eight screenshots, one per category of supported widget: charts, maps and geospatial, 3D, scientific, tables and grids, data exploration, networks, and input and drawing. + +| Category | Libraries | +|------------------------------------|------------------------------------| +| **Charts** | [plotly](https://shinywidgets.org/widgets/plotly/), [altair](https://shinywidgets.org/widgets/altair/), [bokeh](https://shinywidgets.org/widgets/bokeh/), [matplotlib](https://shinywidgets.org/widgets/matplotlib/), [plotnine](https://shinywidgets.org/widgets/plotnine/), [bqplot](https://shinywidgets.org/widgets/bqplot/), [HoloViews](https://shinywidgets.org/widgets/holoviews/) (with [hvPlot](https://shinywidgets.org/widgets/holoviews/), [GeoViews](https://shinywidgets.org/widgets/geoviews/), and [datashader](https://shinywidgets.org/widgets/datashader/)), [jupyter-scatter](https://shinywidgets.org/widgets/jscatter/), [Observable Plot](https://shinywidgets.org/widgets/obsplot/), [Panel](https://shinywidgets.org/widgets/panel/) | +| **Maps & geospatial** | [ipyleaflet](https://shinywidgets.org/widgets/ipyleaflet/), [leafmap](https://shinywidgets.org/widgets/leafmap/), [MapLibre](https://shinywidgets.org/widgets/maplibre/), [lonboard](https://shinywidgets.org/widgets/lonboard/), [GeoLibre](https://shinywidgets.org/widgets/geolibre/), [kepler.gl](https://shinywidgets.org/widgets/keplergl/) | +| **Tables & grids** | [itables](https://shinywidgets.org/widgets/itables/), [reactable](https://shinywidgets.org/widgets/reactable/), [ipydatagrid](https://shinywidgets.org/widgets/ipydatagrid/), [Perspective](https://shinywidgets.org/widgets/perspective/) | +| **Data exploration** | [PyGWalker](https://shinywidgets.org/widgets/pygwalker/), [quak](https://shinywidgets.org/widgets/quak/), [Mosaic](https://shinywidgets.org/widgets/mosaic/), [Embedding Atlas](https://shinywidgets.org/widgets/embedding-atlas/) | +| **3D** | [k3d](https://shinywidgets.org/widgets/k3d/), [pythreejs](https://shinywidgets.org/widgets/pythreejs/), [PyVista](https://shinywidgets.org/widgets/pyvista/), [ipyvolume](https://shinywidgets.org/widgets/ipyvolume/) | +| **Scientific** | [mols2grid](https://shinywidgets.org/widgets/mols2grid/), [nglview](https://shinywidgets.org/widgets/nglview/), [vizarr](https://shinywidgets.org/widgets/vizarr/), [NiiVue](https://shinywidgets.org/widgets/niivue/), [ipyaladin](https://shinywidgets.org/widgets/ipyaladin/), [Rerun](https://shinywidgets.org/widgets/rerun/) | +| **Networks** | [ipycytoscape](https://shinywidgets.org/widgets/ipycytoscape/), [ipysigma](https://shinywidgets.org/widgets/ipysigma/) | +| **Input & drawing** | [drawdata](https://shinywidgets.org/widgets/drawdata/), [ipycanvas](https://shinywidgets.org/widgets/ipycanvas/), [ipyfilechooser](https://shinywidgets.org/widgets/ipyfilechooser/) | + +
+
+Don't see your library? +
+
+ +It may still work. +`@render_widget` renders any [ipywidget](https://ipywidgets.readthedocs.io/en/stable/), including [anywidget](https://anywidget.dev)-based ones you write yourself. +I can't test every widget out there --- if yours doesn't work, please [let me know](https://github.com/posit-dev/py-shinywidgets/issues). + +
+
+ +### Gallery + +The site has a [gallery](https://shinywidgets.org/gallery/) of complete apps, and its [home page](https://shinywidgets.org) features six of them. +This video steps through each one, showing the app as it loads and then after a click, lasso, or brush: + + + + + + + +Those are just the highlights --- visit the [gallery](https://shinywidgets.org/gallery/) for all 18 complete apps and 17 smaller templates, each with source code. + +### Guides + +- **New to shinywidgets?** Start with [Why shinywidgets?](https://shinywidgets.org/guide/why/) and [Your first widget app](https://shinywidgets.org/guide/first-app/), which runs in your browser via [Shinylive](https://shiny.posit.co/py/get-started/shinylive.html). +- **[Choosing a widget](https://shinywidgets.org/guide/choosing-a-widget/)** compares libraries by task and data size. +- **[Linking widgets](https://shinywidgets.org/guide/linked-views/)** covers eight patterns for making widgets react to each other. +- **[Updating in place](https://shinywidgets.org/guide/updating-in-place/)** changes a widget without re-rendering it, keeping the user's zoom and shrinking a plotly recolor from 5.5 MB to 36 KB. +- **[Large data & performance](https://shinywidgets.org/guide/performance/)** benchmarks three ways to scale to millions of points. +- **[AI exploration](https://shinywidgets.org/guide/ai-exploration/)** pairs widgets with an LLM chat that can read and drive them. +- **[Any widget](https://shinywidgets.org/guide/any-widget/)** covers libraries without their own decorator, and writing your own. + +### For your coding agent + +Most of shinywidgets 1.0 is newer than what coding agents were trained on. +So the package ships an [Agent Skill](https://agentskills.io): the guides and widget pages above, condensed for agents and matched to the version you have installed. +To try it, paste this into your coding agent. It sets up a project, installs the skill, brainstorms app ideas with you, then builds one: + +``` text +Help me build a Shiny for Python app with linked, interactive widgets +using shinywidgets. + +1. Set up: create a uv project (`uv init`, `uv add shinywidgets`), then + run `uvx library-skills -s shinywidgets --yes` (add `--claude` if + you're Claude Code) and read the skill it installs. +2. Brainstorm with me: ask what data I have (or suggest an interesting + public dataset) and what I want to learn from it, one question at a + time. Then pitch three app ideas where widgets react to each other, + at least one using a library I probably haven't tried. +3. Build it: once I pick one, install the extras it needs, build the + app, run it in the background, and give me the URL and what to click + first. +``` + +## Reactive accessors + +Rendering a widget hasn't changed. +A `@render_*` function returns whatever you'd show in a notebook, and users get a widget they can click, hover, select, pan, and so on: + +``` python +df = px.data.gapminder().query("year == 2007") + +@render_plotly +def plot(): + return px.scatter(df, x="gdpPercap", y="lifeExp", log_x=True) +``` + +Doing something with those interactions in a larger app can be challenging. +That's because some interactions fire callbacks (e.g., `on_click()`), others update a synced property (e.g., an ipyleaflet map's `bounds`), and each widget has its own APIs to learn. + +The new [reactive accessors](https://shinywidgets.org/guide/reacting-to-widgets/) API in 1.0 aims to unify and simplify how you work with widget interactions. +They behave much like any other Shiny input and aim to be as consistent as possible across widgets. +For instance, `plot.selected()` reactively reads what the user selected on a plot, and is available for plotly, altair, bokeh, and more. For a full list of accessors, see the [accessor cheat sheet](https://shinywidgets.org/guide/reacting-to-widgets/cheatsheet.html). + +Since accessors are methods, they can also provide documentation and type hints, making it easier to understand how to use them and what data they return. +Reactive accessors also handle the fiddly parts of event handling, like debouncing rapid interactions, firing on repeat clicks, and keeping values across a re-render. + +To get a feel for them, here are a few examples, each turning an interaction into something else in the app. + +### Lasso to table + +With selection reporting turned on via `@render_plotly(listen_to=)`, `plot.selected_rows(df)` returns the rows of your data frame that the user lassoed. + +``` python { filename="app.py" shinylive="https://shinylive.io/py/editor/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMASxlWICcyACVAG2LPewzgA9UjOAGcRLKONT8AOhABmjYjBYiAFjQi8BQ0eLoNmLYRAAmcRnhYBXGnMXLVGrQHcapgOZwy++k1Ym5owA+hxcPHJypvIsALxs-BimUGRQGB5oMJpBABQAlBgAjtYW2DkyYNhwUIxx8QBMAAyNAOwVeZEQtlhQXsHEqD45ZDTccLEVADKSIsQsZHOpAEbscBVW8jTs7FAr4wAqjCUdEHJuZGo2NBg72MTWZMEk7NYwECI5z8FuphciscAWlYAKwAXTyiDkLGhLHOl26hBqphy8ms22CIkIwkosUOx0hEBhRKuGERjFMwTU1VyUxmc1m8BYJGs5EYNFE7U6xJhAAFAhZQpxuGV2DQRBQIMEFgCKiI4KtCBQKUoXCIKuCodyWOYYmEyPkCVriZsPHEEhhMSkKIwctErPwJmAPKZUAAFCyI1DrFjYR2i+RwACigm9nA8wQdeLgVkI1nFymCyVSAOiGGyAg1hKNMOEZGsjEJJow1lQSbgwVu931pkYvRgxHMfrpnNOWehcJJZORqPRmOxEFxRzgEM13IRSMp1Is5TAAGV5XBFXBTEz7qz2WqwCdR8S+ZQgkkUlBgopYGs28SdaoF0vkSOL0bc-nCXqLTelcEVR9oicwABfPBwGgeBqGEYoaGEeByBEDAyH4Mh8CIUgJQQ5B1E0bAfi8Hw5D1CIIFQKAzEkOR-1BIA" } +from shiny.express import render + +@render_plotly(listen_to=["selected_rows"]) +def plot(): + fig = px.scatter(df, x="gdpPercap", y="lifeExp", log_x=True, custom_data=[df.index]) + return fig.update_layout(dragmode="lasso") + +@render.data_frame +def selected(): + return plot.selected_rows(df) +``` + +A Shiny app with two cards. On the left, a bubble chart of life expectancy against GDP per capita with a lasso drawn around the wealthier countries. On the right, a table listing the 72 selected countries. + +
+
+More plotly accessors +
+
+ +`@render_plotly` also has `.clicked()`, `.hover()`, `.relayout()`, and more, borrowed from `event_data()` in the R [plotly](https://plotly-r.com) package, which I also maintain. +[Reacting to widgets](https://shinywidgets.org/guide/reacting-to-widgets/) covers them all. + +
+
+ +### Map to chart + +Next, an ipyleaflet map of Montreal car-share pods drives a plotly histogram of just the pods currently in view, so panning or zooming the map updates the chart. + +``` python { filename="app.py" shinylive="https://shinylive.io/py/editor/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMASxlWICcyACGnAGzigDMvWoAZxYAZADoQ6DZi1RQIAEyEtlqBRKlNWqDsTIdsGOAA9UjOIOGrjEno2IwWggBY0Ihk2YvDNMgK40tvaOLm7YAO40CgDmcGQ+9Fos5opwjAD67NhcvPx4yZQKaek6egYSEgDEssQKgoiyuvrYAOTChFCMLp1wLEpkUPmRZM4qLGJgqGk0tRMsJBx+MBAsPEws3ISjDAptLABGfoI0FqxkdL3EPH1Q2BI7wgC8ssYY-VAYHV3OPQAUAJT3WqCYATKaMGbqMAAXRYzzUnz8ZF+EhYaJqdVBk24AGt0s5iH5GBNofl9m5BI9gABaACM+QArPlafSWLSAOz5ABMAGZSSwOFB9nAOJSsZJos4yBN8hMYExJBBojLxigeBRGBBiKQVRM4AA3ShuZUwiSAiASAJYKCxdLEVDxX7nfRwR4TADqPzIezcLH1J3CKp4NA4gv2XEeABVGH44OaJMNRlbBdhCWR0gslhBBL8FulIgoRmLOSwGdD-ohUejEywrV8FADKxaVujWwABFJFDJZHJ8OJV1toorXHbpGBoRsDwetxzPEQYACyE8IlA1j1+ABYGRgGVz8tT2TydwBOf75ABe2pgjxZ5un0-HjBxaSeLGA86XT7Sv10HXOpHXRhPlXewonSQUyHyICV3IUCFHA0h-n+VZ1kYNgVgeDAaA1Mg-B0CwAWhKd7xYGAMCgBQGw-Tpn0YABhRZBA1X5H1oylWJfJDiPvcxcM1UiKhbNEazrToGwrbi0VExh4OcbguxRMAAAVgXQv0AzJbADiOE4mJYc54BYK4bjuMB4yEwcO0KYpSmaSS+jga43HSf04HCScLJI35BDTZwhlOM8WF+LVmD8jYhDIZD4VqMc0AwfZCUUHM7xI9F-WOcNemizFMJgsg4PAqAyHiuJwjgShvN8-IQpGZCADIMUEYDYOIMDdAgEqyDKiqyqY-JuCY-4iM8ni4iJDDXlcJjiGiRhYF+dKaEy-JjDdbEIVmMyJDAABfPBwGgeBqHMABHAJzHgcgmrIYwyHwIhSAoKhkFCdwC1ieINE4bg+2lCBbPKf75CUQRtp26EgA" } +# pods: plotly's carshare data, with a "period" column for each pod's busiest time of day + +@render_ipyleaflet +def pod_map(): + ... # an ipyleaflet Map with a marker for every pod + +@render_plotly +def in_view(): + (south, west), (north, east) = pod_map.bounds() + visible = pods[pods.centroid_lat.between(south, north) & pods.centroid_lon.between(west, east)] + return px.histogram(visible, x="period") +``` + +An app titled 'What's in view'. On the left, a street map of Montreal with clustered car-share markers. On the right, a bar chart counting the pods in the current view by the time of day they're busiest. + +### Selection to chat + +Accessors can be read from any code, including a tool that an LLM calls. +Below, a [chatlas](https://posit-dev.github.io/chatlas/) `client` gets a tool that returns the countries lassoed on the plot above, and a [shinychat](https://posit-dev.github.io/shinychat/) `Chat` passes along the user's questions. + +``` python +def get_selection() -> str: + """The countries the user lassoed on the scatter plot.""" + with reactive.isolate(): # temporary workaround to read reactive state in a tool call + rows = plot.selected_rows(df) + return rows[["country", "gdpPercap", "lifeExp"]].to_csv(index=False) + +client = chatlas.ChatAnthropic() +client.register_tool(get_selection) +chat = Chat("chat", client=client) +``` + +In the screenshot below, I lassoed the handful of countries sitting well below the curve and asked why. +The model called the tool to find out which countries I meant, then explained the gap using things it knows that aren't in the data, like HIV/AIDS and oil and diamond wealth that never reaches most people. + +An app with a scatter plot of GDP per capita against life expectancy, with four African countries selected well below the trend, beside a chat panel where the assistant explains that HIV/AIDS, resource wealth that doesn't reach most people, and inequality keep life expectancy low despite relatively high incomes. + +Tools can go the other direction too. +One that sets `map.widget.center` lets the model move a map when asked. +[AI exploration](https://shinywidgets.org/guide/ai-exploration/) has examples of both. + +### Any widget + +Widgets without their own decorator don't get named accessors, but under `@render_widget`, `.read()` reactively reads any synced property, so even a custom [anywidget](https://anywidget.dev) can drive the rest of your app. + +``` python {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t4c9cgC9-6lSVUhIidw1MKz0g99y+sJKB6J9O0bofkj6boLADKiK-oiK59d5k9eK4QBKS9mSaUM9ZKvQm9LG0Gpq5qlqA9NqV6TkkqboC+6RSZNolKO0zKrKw93exKvK7ef11ev92tGe1K0elyYlEq7oCqcg5eKq7ehIwN0tWq-oaU1IGDnwbRdE0af9LWuaKaaaLAGaHaOaSarDA9FxvYUGg65aktZZAYJM+gcwpYpSv9UGXa-1UsGANDz9JamEQ6ro8d45AoyW4Zd+GWoeNl6c8d4m7GLIGjzIs5Ogtli5l0Z0j03yR1u1hA5FRFMC1F-upQMlrF9tPVGwylrloVGlnli4y4kAuV1AapZgagEMviGSx4+4htVAyAMgtMVs6035UYzVOA84C4tIQAA" } +@render_widget +def spark(): + return Sparkline(values=data) # a custom anywidget + +@render.code +def clicked(): + return spark.read("clicked_index") +``` + +[Linking widgets](https://shinywidgets.org/guide/linked-views/) has more patterns like these. + +## Many improvements + +Besides the new decorators and accessors, 1.0 fixes a lot of long-standing rough edges. +Most of these fixes help every widget, including ones without a dedicated decorator. + +### Widgets that render right + +- **More nested widgets render.** Some widgets nested inside other widgets, like a plotly chart in an ipyleaflet popup, didn't render at all, and others, like leafmap legends, rendered while logging errors. + A newer version of the JavaScript that renders Jupyter widgets fixes both, along with widgets built on [ipyreact](https://github.com/widgetti/ipyreact) and icon fonts like FontAwesome. +- **Widgets fit your layout.** They fill their container in filling layouts (e.g., a card), respect an explicit `output_widget(height=...)`, and keep any size you set on the widget itself. + That also fixes cases where a plot collapsed to a sliver or ignored the height you gave it. + Some widgets, like ipydatagrid and bqplot, follow the app's dark mode too. + [Layout & theming](https://shinywidgets.org/guide/layout-and-theming/) has the details. +- **Fewer silent failures.** A widget that breaks after its render function returns now shows an error instead of a blank output, and exceptions in handlers like `on_click()` reach the server log. + Widget methods called before the output finishes rendering, like k3d's `start_auto_play()`, are no longer dropped. + +### Apps with many visitors + +Jupyter widgets were designed for notebooks, which usually means one person with one kernel on their own machine. +With Shiny, one Python process can serve many visitors at once, user sessions come and go, and the app may run for weeks. + +- **Each visitor gets their own state.** `@render_matplotlib`, for example, keeps pyplot's global state separate per session. + Returning a widget that belongs to another session now raises a clear error, and [`session_lifetime()` and `shared_lifetime()`](https://shinywidgets.org/guide/updating-in-place/#lifetimes) let you cache or share a widget when you mean to. +- **Memory is freed sooner.** Re-rendering, hiding, or removing an output could leave the old widget, and the data it held, in memory until the session ended. + Those cases are fixed on both the server and in the browser, so widgets are freed as soon as they're replaced or removed. +- **One oversized message no longer disconnects a visitor.** It's dropped with a notification instead. +- **Widgets that assumed a local machine work on a server.** localtileserver raster layers load on Posit Connect and shinyapps.io with no extra code, and widgets that run SQL from the browser (quak, Mosaic, Embedding Atlas) are blocked from reading the server's files by default. + [Deployment](https://shinywidgets.org/guide/deployment/) covers the rest. + +### Other improvements + +- **Clearer errors for things that aren't widgets.** Returning something that can't be rendered as a widget, like a string, now gets a clearer error message. +- **Plotly config options.** `@render_plotly` now accepts a Dash-style `(fig, config)` return value, for [Plotly.js config options](https://plotly.com/javascript/configuration-options/) like hiding the toolbar with `{"displayModeBar": False}`. +- **Bokeh assets load automatically**, including those for [extension models](https://docs.bokeh.org/en/latest/docs/user_guide/advanced/extensions.html) and in apps mounted under a URL prefix, so you no longer need `bokeh_dependency()` in your UI. +- **Updates from background threads arrive right away.** With shiny 1.9, widget updates made from a background thread (e.g., nglview's, or your own `threading.Thread`) reach the browser right away instead of waiting for the visitor's next input. + +The [changelog](https://shinywidgets.org/changelog.html) has the full list. + +## Upgrading + +Most apps should upgrade without changes. +shinywidgets 1.0 requires shiny 1.9 and ipywidgets 8.1, plus plotly 5.12 if you use plotly. +The one change most likely to affect an existing app is that `@render_plotly` no longer sends plotly's own click, hover, and selection events to Python unless the app uses them. +If a plotly callback registered outside the render function stops firing, turn them back on with `shinywidgets.config(native_events=True)`. +The [changelog](https://shinywidgets.org/changelog.html) lists every breaking change and deprecation. + +## Thanks, and what's next + +In a lot of ways, shinywidgets 1.0 is a celebration of other people's work, from the 40+ libraries above to projects like [anywidget](https://anywidget.dev) that make new widgets easy to write. +Thank you to everyone who built them, and especially to the maintainers who welcomed fixes and reports from upstream: [@manzt](https://github.com/manzt) (anywidget), [@giswqs](https://github.com/giswqs) (GeoLibre), [@koaning](https://github.com/koaning) (drawdata), [@texodus](https://github.com/texodus) (Perspective), [@philippjfr](https://github.com/philippjfr) (Panel), and [@juba](https://github.com/juba) (pyobsplot). + +If a library you rely on doesn't have its own decorator yet, you can help! +The repo includes an [agent skill for adding integrations](https://github.com/posit-dev/py-shinywidgets/tree/main/.agents/skills/adding-shinywidgets-integrations) that takes a coding agent from "does this widget even work?" to a decorator, sizing, accessors, and a guide, checking each step in a real browser. +Each new integration can surface another failure mode in the logic every widget shares, so Pull Requests are very welcome, and so is an [Issue](https://github.com/posit-dev/py-shinywidgets/issues) that just says what didn't work. + +So go bring your Jupyter widgets to Shiny, and if you build something neat, I'd love to see it! +You can find me on socials via my [profile page](../../people/carson-sievert/). diff --git a/content/blog/shinywidgets-1-0/index.qmd b/content/blog/shinywidgets-1-0/index.qmd new file mode 100644 index 000000000..b060bb31f --- /dev/null +++ b/content/blog/shinywidgets-1-0/index.qmd @@ -0,0 +1,294 @@ +--- +title: "shinywidgets 1.0: bring your Jupyter widgets to Shiny" +date: 2026-12-08 +people: + - Carson Sievert + - Shiny Team +description: > + shinywidgets 1.0 brings dedicated support for 40+ interactive Python + libraries to Shiny, plus a new website and a simpler way to react to clicks, + selections, and other user interactions. +image: featured.jpg +image-video: featured.mp4 +image-alt: > + The words "shinywidgets 1.0: Bring your Jupyter widgets to Shiny" beside a + wall of widget screenshots, including a map of US counties, a protein + structure, ship tracks, a brain scan, 3D terrain, and a molecule grid. +topics: + - Interactive Apps + - Visualization +software: + - py-shinywidgets + - shiny-python +languages: + - Python +source: shiny +hidesubscription: false +--- + +I'm excited to announce that [shinywidgets 1.0](https://pypi.org/project/shinywidgets/) is now on PyPI! Grab it now with: + +```bash +pip install -U shinywidgets +``` + +In principle, shinywidgets lets you use any Jupyter widget library (plotly, altair, and so on) in [Shiny](https://shiny.posit.co/py/). +In practice, most widgets are written for one person's notebook, and many need workarounds before they reliably load, size, re-render, and scale to many concurrent users. +In 1.0, dozens of libraries get those workarounds built in, and the failure modes they had in common led to fixes in the logic every widget shares. + +Integrations are the bulk of this release, but not all of it. Here are the highlights: + +- [Support for 40+ libraries](#40-integrations), documented on a [new website](#a-new-website) and in an [agent skill](#for-your-coding-agent). +- [Reactive accessors](#reactive-accessors) that turn common interactions, from a click to a map pan, into reactive values. +- [Many fixes and improvements](#many-improvements), especially for widgets in deployed, multi-user apps. + +If you're upgrading an existing app, see [Upgrading](#upgrading) for the few things to check. + +## A new website + +[shinywidgets.org](https://shinywidgets.org) has a guide for every supported library, a gallery of complete apps, and longer guides on everything from choosing a widget to keeping an app fast. + +The shinywidgets.org homepage, with the headline 'Bring your Jupyter widgets to Shiny' over a tiled wall of widget app screenshots, and buttons to get started or browse the gallery. + +### 40+ integrations + +Before 1.0, only three libraries had their own decorator. +Everything else went through the generic `@render_widget`, and often needed extra work to look and behave right. +Now 40+ libraries each get their own decorator (e.g., `@render_geolibre`), an install extra (e.g., `pip install 'shinywidgets[geolibre]'`), sizing that fits Shiny's layouts, and a guide with runnable examples. +The table below groups them by what you're building, and each name links to its guide. + +Eight screenshots, one per category of supported widget: charts, maps and geospatial, 3D, scientific, tables and grids, data exploration, networks, and input and drawing. + +| Category | Libraries | +|---|---| +| **Charts** | [plotly](https://shinywidgets.org/widgets/plotly/), [altair](https://shinywidgets.org/widgets/altair/), [bokeh](https://shinywidgets.org/widgets/bokeh/), [matplotlib](https://shinywidgets.org/widgets/matplotlib/), [plotnine](https://shinywidgets.org/widgets/plotnine/), [bqplot](https://shinywidgets.org/widgets/bqplot/), [HoloViews](https://shinywidgets.org/widgets/holoviews/) (with [hvPlot](https://shinywidgets.org/widgets/holoviews/), [GeoViews](https://shinywidgets.org/widgets/geoviews/), and [datashader](https://shinywidgets.org/widgets/datashader/)), [jupyter-scatter](https://shinywidgets.org/widgets/jscatter/), [Observable Plot](https://shinywidgets.org/widgets/obsplot/), [Panel](https://shinywidgets.org/widgets/panel/) | +| **Maps & geospatial** | [ipyleaflet](https://shinywidgets.org/widgets/ipyleaflet/), [leafmap](https://shinywidgets.org/widgets/leafmap/), [MapLibre](https://shinywidgets.org/widgets/maplibre/), [lonboard](https://shinywidgets.org/widgets/lonboard/), [GeoLibre](https://shinywidgets.org/widgets/geolibre/), [kepler.gl](https://shinywidgets.org/widgets/keplergl/) | +| **Tables & grids** | [itables](https://shinywidgets.org/widgets/itables/), [reactable](https://shinywidgets.org/widgets/reactable/), [ipydatagrid](https://shinywidgets.org/widgets/ipydatagrid/), [Perspective](https://shinywidgets.org/widgets/perspective/) | +| **Data exploration** | [PyGWalker](https://shinywidgets.org/widgets/pygwalker/), [quak](https://shinywidgets.org/widgets/quak/), [Mosaic](https://shinywidgets.org/widgets/mosaic/), [Embedding Atlas](https://shinywidgets.org/widgets/embedding-atlas/) | +| **3D** | [k3d](https://shinywidgets.org/widgets/k3d/), [pythreejs](https://shinywidgets.org/widgets/pythreejs/), [PyVista](https://shinywidgets.org/widgets/pyvista/), [ipyvolume](https://shinywidgets.org/widgets/ipyvolume/) | +| **Scientific** | [mols2grid](https://shinywidgets.org/widgets/mols2grid/), [nglview](https://shinywidgets.org/widgets/nglview/), [vizarr](https://shinywidgets.org/widgets/vizarr/), [NiiVue](https://shinywidgets.org/widgets/niivue/), [ipyaladin](https://shinywidgets.org/widgets/ipyaladin/), [Rerun](https://shinywidgets.org/widgets/rerun/) | +| **Networks** | [ipycytoscape](https://shinywidgets.org/widgets/ipycytoscape/), [ipysigma](https://shinywidgets.org/widgets/ipysigma/) | +| **Input & drawing** | [drawdata](https://shinywidgets.org/widgets/drawdata/), [ipycanvas](https://shinywidgets.org/widgets/ipycanvas/), [ipyfilechooser](https://shinywidgets.org/widgets/ipyfilechooser/) | + +::: {.callout-tip title="Don't see your library?"} +It may still work. +`@render_widget` renders any [ipywidget](https://ipywidgets.readthedocs.io/en/stable/), including [anywidget](https://anywidget.dev)-based ones you write yourself. +I can't test every widget out there — if yours doesn't work, please [let me know](https://github.com/posit-dev/py-shinywidgets/issues). +::: + +### Gallery + +The site has a [gallery](https://shinywidgets.org/gallery/) of complete apps, and its [home page](https://shinywidgets.org) features six of them. +This video steps through each one, showing the app as it loads and then after a click, lasso, or brush: + + + +Those are just the highlights — visit the [gallery](https://shinywidgets.org/gallery/) for all 18 complete apps and 17 smaller templates, each with source code. + +### Guides + +- **New to shinywidgets?** Start with [Why shinywidgets?](https://shinywidgets.org/guide/why/) and [Your first widget app](https://shinywidgets.org/guide/first-app/), which runs in your browser via [Shinylive](https://shiny.posit.co/py/get-started/shinylive.html). +- **[Choosing a widget](https://shinywidgets.org/guide/choosing-a-widget/)** compares libraries by task and data size. +- **[Linking widgets](https://shinywidgets.org/guide/linked-views/)** covers eight patterns for making widgets react to each other. +- **[Updating in place](https://shinywidgets.org/guide/updating-in-place/)** changes a widget without re-rendering it, keeping the user's zoom and shrinking a plotly recolor from 5.5 MB to 36 KB. +- **[Large data & performance](https://shinywidgets.org/guide/performance/)** benchmarks three ways to scale to millions of points. +- **[AI exploration](https://shinywidgets.org/guide/ai-exploration/)** pairs widgets with an LLM chat that can read and drive them. +- **[Any widget](https://shinywidgets.org/guide/any-widget/)** covers libraries without their own decorator, and writing your own. + +### For your coding agent + +Most of shinywidgets 1.0 is newer than what coding agents were trained on. +So the package ships an [Agent Skill](https://agentskills.io): the guides and widget pages above, condensed for agents and matched to the version you have installed. +To try it, paste this into your coding agent. It sets up a project, installs the skill, brainstorms app ideas with you, then builds one: + +```text +Help me build a Shiny for Python app with linked, interactive widgets +using shinywidgets. + +1. Set up: create a uv project (`uv init`, `uv add shinywidgets`), then + run `uvx library-skills -s shinywidgets --yes` (add `--claude` if + you're Claude Code) and read the skill it installs. +2. Brainstorm with me: ask what data I have (or suggest an interesting + public dataset) and what I want to learn from it, one question at a + time. Then pitch three app ideas where widgets react to each other, + at least one using a library I probably haven't tried. +3. Build it: once I pick one, install the extras it needs, build the + app, run it in the background, and give me the URL and what to click + first. +``` + +## Reactive accessors + +Rendering a widget hasn't changed. +A `@render_*` function returns whatever you'd show in a notebook, and users get a widget they can click, hover, select, pan, and so on: + +```python +df = px.data.gapminder().query("year == 2007") + +@render_plotly +def plot(): + return px.scatter(df, x="gdpPercap", y="lifeExp", log_x=True) +``` + +Doing something with those interactions in a larger app can be challenging. +That's because some interactions fire callbacks (e.g., `on_click()`), others update a synced property (e.g., an ipyleaflet map's `bounds`), and each widget has its own APIs to learn. + +The new [reactive accessors](https://shinywidgets.org/guide/reacting-to-widgets/) API in 1.0 aims to unify and simplify how you work with widget interactions. +They behave much like any other Shiny input and aim to be as consistent as possible across widgets. +For instance, `plot.selected()` reactively reads what the user selected on a plot, and is available for plotly, altair, bokeh, and more. For a full list of accessors, see the [accessor cheat sheet](https://shinywidgets.org/guide/reacting-to-widgets/cheatsheet.html). + +Since accessors are methods, they can also provide documentation and type hints, making it easier to understand how to use them and what data they return. +Reactive accessors also handle the fiddly parts of event handling, like debouncing rapid interactions, firing on repeat clicks, and keeping values across a re-render. + +To get a feel for them, here are a few examples, each turning an interaction into something else in the app. + +### Lasso to table + +With selection reporting turned on via `@render_plotly(listen_to=)`, `plot.selected_rows(df)` returns the rows of your data frame that the user lassoed. + +````{=markdown} +``` python { filename="app.py" shinylive="https://shinylive.io/py/editor/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMASxlWICcyACVAG2LPewzgA9UjOAGcRLKONT8AOhABmjYjBYiAFjQi8BQ0eLoNmLYRAAmcRnhYBXGnMXLVGrQHcapgOZwy++k1Ym5owA+hxcPHJypvIsALxs-BimUGRQGB5oMJpBABQAlBgAjtYW2DkyYNhwUIxx8QBMAAyNAOwVeZEQtlhQXsHEqD45ZDTccLEVADKSIsQsZHOpAEbscBVW8jTs7FAr4wAqjCUdEHJuZGo2NBg72MTWZMEk7NYwECI5z8FuphciscAWlYAKwAXTyiDkLGhLHOl26hBqphy8ms22CIkIwkosUOx0hEBhRKuGERjFMwTU1VyUxmc1m8BYJGs5EYNFE7U6xJhAAFAhZQpxuGV2DQRBQIMEFgCKiI4KtCBQKUoXCIKuCodyWOYYmEyPkCVriZsPHEEhhMSkKIwctErPwJmAPKZUAAFCyI1DrFjYR2i+RwACigm9nA8wQdeLgVkI1nFymCyVSAOiGGyAg1hKNMOEZGsjEJJow1lQSbgwVu931pkYvRgxHMfrpnNOWehcJJZORqPRmOxEFxRzgEM13IRSMp1Is5TAAGV5XBFXBTEz7qz2WqwCdR8S+ZQgkkUlBgopYGs28SdaoF0vkSOL0bc-nCXqLTelcEVR9oicwABfPBwGgeBqGEYoaGEeByBEDAyH4Mh8CIUgJQQ5B1E0bAfi8Hw5D1CIIFQKAzEkOR-1BIA" } +from shiny.express import render + +@render_plotly(listen_to=["selected_rows"]) +def plot(): + fig = px.scatter(df, x="gdpPercap", y="lifeExp", log_x=True, custom_data=[df.index]) + return fig.update_layout(dragmode="lasso") + +@render.data_frame +def selected(): + return plot.selected_rows(df) +``` +```` + +A Shiny app with two cards. On the left, a bubble chart of life expectancy against GDP per capita with a lasso drawn around the wealthier countries. On the right, a table listing the 72 selected countries. + +::: {.callout-tip title="More plotly accessors"} +`@render_plotly` also has `.clicked()`, `.hover()`, `.relayout()`, and more, borrowed from `event_data()` in the R [plotly](https://plotly-r.com) package, which I also maintain. +[Reacting to widgets](https://shinywidgets.org/guide/reacting-to-widgets/) covers them all. +::: + +### Map to chart + +Next, an ipyleaflet map of Montreal car-share pods drives a plotly histogram of just the pods currently in view, so panning or zooming the map updates the chart. + +````{=markdown} +``` python { filename="app.py" shinylive="https://shinylive.io/py/editor/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMASxlWICcyACGnAGzigDMvWoAZxYAZADoQ6DZi1RQIAEyEtlqBRKlNWqDsTIdsGOAA9UjOIOGrjEno2IwWggBY0Ihk2YvDNMgK40tvaOLm7YAO40CgDmcGQ+9Fos5opwjAD67NhcvPx4yZQKaek6egYSEgDEssQKgoiyuvrYAOTChFCMLp1wLEpkUPmRZM4qLGJgqGk0tRMsJBx+MBAsPEws3ISjDAptLABGfoI0FqxkdL3EPH1Q2BI7wgC8ssYY-VAYHV3OPQAUAJT3WqCYATKaMGbqMAAXRYzzUnz8ZF+EhYaJqdVBk24AGt0s5iH5GBNofl9m5BI9gABaACM+QArPlafSWLSAOz5ABMAGZSSwOFB9nAOJSsZJos4yBN8hMYExJBBojLxigeBRGBBiKQVRM4AA3ShuZUwiSAiASAJYKCxdLEVDxX7nfRwR4TADqPzIezcLH1J3CKp4NA4gv2XEeABVGH44OaJMNRlbBdhCWR0gslhBBL8FulIgoRmLOSwGdD-ohUejEywrV8FADKxaVujWwABFJFDJZHJ8OJV1toorXHbpGBoRsDwetxzPEQYACyE8IlA1j1+ABYGRgGVz8tT2TydwBOf75ABe2pgjxZ5un0-HjBxaSeLGA86XT7Sv10HXOpHXRhPlXewonSQUyHyICV3IUCFHA0h-n+VZ1kYNgVgeDAaA1Mg-B0CwAWhKd7xYGAMCgBQGw-Tpn0YABhRZBA1X5H1oylWJfJDiPvcxcM1UiKhbNEazrToGwrbi0VExh4OcbguxRMAAAVgXQv0AzJbADiOE4mJYc54BYK4bjuMB4yEwcO0KYpSmaSS+jga43HSf04HCScLJI35BDTZwhlOM8WF+LVmD8jYhDIZD4VqMc0AwfZCUUHM7xI9F-WOcNemizFMJgsg4PAqAyHiuJwjgShvN8-IQpGZCADIMUEYDYOIMDdAgEqyDKiqyqY-JuCY-4iM8ni4iJDDXlcJjiGiRhYF+dKaEy-JjDdbEIVmMyJDAABfPBwGgeBqHMABHAJzHgcgmrIYwyHwIhSAoKhkFCdwC1ieINE4bg+2lCBbPKf75CUQRtp26EgA" } +# pods: plotly's carshare data, with a "period" column for each pod's busiest time of day + +@render_ipyleaflet +def pod_map(): + ... # an ipyleaflet Map with a marker for every pod + +@render_plotly +def in_view(): + (south, west), (north, east) = pod_map.bounds() + visible = pods[pods.centroid_lat.between(south, north) & pods.centroid_lon.between(west, east)] + return px.histogram(visible, x="period") +``` +```` + +An app titled 'What's in view'. On the left, a street map of Montreal with clustered car-share markers. On the right, a bar chart counting the pods in the current view by the time of day they're busiest. + +### Selection to chat + +Accessors can be read from any code, including a tool that an LLM calls. +Below, a [chatlas](https://posit-dev.github.io/chatlas/) `client` gets a tool that returns the countries lassoed on the plot above, and a [shinychat](https://posit-dev.github.io/shinychat/) `Chat` passes along the user's questions. + +```python +def get_selection() -> str: + """The countries the user lassoed on the scatter plot.""" + with reactive.isolate(): # temporary workaround to read reactive state in a tool call + rows = plot.selected_rows(df) + return rows[["country", "gdpPercap", "lifeExp"]].to_csv(index=False) + +client = chatlas.ChatAnthropic() +client.register_tool(get_selection) +chat = Chat("chat", client=client) +``` + +In the screenshot below, I lassoed the handful of countries sitting well below the curve and asked why. +The model called the tool to find out which countries I meant, then explained the gap using things it knows that aren't in the data, like HIV/AIDS and oil and diamond wealth that never reaches most people. + +An app with a scatter plot of GDP per capita against life expectancy, with four African countries selected well below the trend, beside a chat panel where the assistant explains that HIV/AIDS, resource wealth that doesn't reach most people, and inequality keep life expectancy low despite relatively high incomes. + +Tools can go the other direction too. +One that sets `map.widget.center` lets the model move a map when asked. +[AI exploration](https://shinywidgets.org/guide/ai-exploration/) has examples of both. + +### Any widget + +Widgets without their own decorator don't get named accessors, but under `@render_widget`, `.read()` reactively reads any synced property, so even a custom [anywidget](https://anywidget.dev) can drive the rest of your app. + +````{=markdown} +``` python { filename="app.py" shinylive="https://shinylive.io/py/editor/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMASxlWICcyACCAV3uxagGc3UAHQgAzRsRgteACxoRsGOAA9UjOL350GzFmogATOIzwt2NYWIlTZ8gO419AczhlN9Jqz2HGAfXtOXYQtxSV5UKEYAawAbOTg-B2dWLQ8WAGVwqNiIOCCDKDIoFgBeFljeMg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YJM+gcwpYpSv9UGXa-1UsGANDz9JamEQ6ro8d45AoyW4Zd+GWoeNl6c8d4m7GLIGjzIs5Ogtli5l0Z0j03yR1u1hA5FRFMC1F-upQMlrF9tPVGwylrloVGlnli4y4kAuV1AapZgagEMviGSx4+4htVAyAMgtMVs6035UYzVOA84C4tIQAA" } +@render_widget +def spark(): + return Sparkline(values=data) # a custom anywidget + +@render.code +def clicked(): + return spark.read("clicked_index") +``` +```` + +[Linking widgets](https://shinywidgets.org/guide/linked-views/) has more patterns like these. + +## Many improvements + +Besides the new decorators and accessors, 1.0 fixes a lot of long-standing rough edges. +Most of these fixes help every widget, including ones without a dedicated decorator. + +### Widgets that render right + +- **More nested widgets render.** Some widgets nested inside other widgets, like a plotly chart in an ipyleaflet popup, didn't render at all, and others, like leafmap legends, rendered while logging errors. + A newer version of the JavaScript that renders Jupyter widgets fixes both, along with widgets built on [ipyreact](https://github.com/widgetti/ipyreact) and icon fonts like FontAwesome. +- **Widgets fit your layout.** They fill their container in filling layouts (e.g., a card), respect an explicit `output_widget(height=...)`, and keep any size you set on the widget itself. + That also fixes cases where a plot collapsed to a sliver or ignored the height you gave it. + Some widgets, like ipydatagrid and bqplot, follow the app's dark mode too. + [Layout & theming](https://shinywidgets.org/guide/layout-and-theming/) has the details. +- **Fewer silent failures.** A widget that breaks after its render function returns now shows an error instead of a blank output, and exceptions in handlers like `on_click()` reach the server log. + Widget methods called before the output finishes rendering, like k3d's `start_auto_play()`, are no longer dropped. + +### Apps with many visitors + +Jupyter widgets were designed for notebooks, which usually means one person with one kernel on their own machine. +With Shiny, one Python process can serve many visitors at once, user sessions come and go, and the app may run for weeks. + +- **Each visitor gets their own state.** `@render_matplotlib`, for example, keeps pyplot's global state separate per session. + Returning a widget that belongs to another session now raises a clear error, and [`session_lifetime()` and `shared_lifetime()`](https://shinywidgets.org/guide/updating-in-place/#lifetimes) let you cache or share a widget when you mean to. +- **Memory is freed sooner.** Re-rendering, hiding, or removing an output could leave the old widget, and the data it held, in memory until the session ended. + Those cases are fixed on both the server and in the browser, so widgets are freed as soon as they're replaced or removed. +- **One oversized message no longer disconnects a visitor.** It's dropped with a notification instead. +- **Widgets that assumed a local machine work on a server.** localtileserver raster layers load on Posit Connect and shinyapps.io with no extra code, and widgets that run SQL from the browser (quak, Mosaic, Embedding Atlas) are blocked from reading the server's files by default. + [Deployment](https://shinywidgets.org/guide/deployment/) covers the rest. + +### Other improvements + +- **Clearer errors for things that aren't widgets.** Returning something that can't be rendered as a widget, like a string, now gets a clearer error message. +- **Plotly config options.** `@render_plotly` now accepts a Dash-style `(fig, config)` return value, for [Plotly.js config options](https://plotly.com/javascript/configuration-options/) like hiding the toolbar with `{"displayModeBar": False}`. +- **Bokeh assets load automatically**, including those for [extension models](https://docs.bokeh.org/en/latest/docs/user_guide/advanced/extensions.html) and in apps mounted under a URL prefix, so you no longer need `bokeh_dependency()` in your UI. +- **Updates from background threads arrive right away.** With shiny 1.9, widget updates made from a background thread (e.g., nglview's, or your own `threading.Thread`) reach the browser right away instead of waiting for the visitor's next input. + + +The [changelog](https://shinywidgets.org/changelog.html) has the full list. + +## Upgrading + +Most apps should upgrade without changes. +shinywidgets 1.0 requires shiny 1.9 and ipywidgets 8.1, plus plotly 5.12 if you use plotly. +The one change most likely to affect an existing app is that `@render_plotly` no longer sends plotly's own click, hover, and selection events to Python unless the app uses them. +If a plotly callback registered outside the render function stops firing, turn them back on with `shinywidgets.config(native_events=True)`. +The [changelog](https://shinywidgets.org/changelog.html) lists every breaking change and deprecation. + +## Thanks, and what's next + +In a lot of ways, shinywidgets 1.0 is a celebration of other people's work, from the 40+ libraries above to projects like [anywidget](https://anywidget.dev) that make new widgets easy to write. +Thank you to everyone who built them, and especially to the maintainers who welcomed fixes and reports from upstream: [@manzt](https://github.com/manzt) (anywidget), [@giswqs](https://github.com/giswqs) (GeoLibre), [@koaning](https://github.com/koaning) (drawdata), [@texodus](https://github.com/texodus) (Perspective), [@philippjfr](https://github.com/philippjfr) (Panel), and [@juba](https://github.com/juba) (pyobsplot). + +If a library you rely on doesn't have its own decorator yet, you can help! +The repo includes an [agent skill for adding integrations](https://github.com/posit-dev/py-shinywidgets/tree/main/.agents/skills/adding-shinywidgets-integrations) that takes a coding agent from "does this widget even work?" to a decorator, sizing, accessors, and a guide, checking each step in a real browser. +Each new integration can surface another failure mode in the logic every widget shares, so Pull Requests are very welcome, and so is an [Issue](https://github.com/posit-dev/py-shinywidgets/issues) that just says what didn't work. + +So go bring your Jupyter widgets to Shiny, and if you build something neat, I'd love to see it! +You can find me on socials via my [profile page](/people/carson-sievert/). diff --git a/content/blog/shinywidgets-1-0/lasso.webp b/content/blog/shinywidgets-1-0/lasso.webp new file mode 100644 index 000000000..b18c471e8 Binary files /dev/null and b/content/blog/shinywidgets-1-0/lasso.webp differ diff --git a/content/blog/shinywidgets-1-0/viewport.webp b/content/blog/shinywidgets-1-0/viewport.webp new file mode 100644 index 000000000..52cf7598f Binary files /dev/null and b/content/blog/shinywidgets-1-0/viewport.webp differ diff --git a/content/blog/shinywidgets-1-0/website-home.webp b/content/blog/shinywidgets-1-0/website-home.webp new file mode 100644 index 000000000..8e89620f5 Binary files /dev/null and b/content/blog/shinywidgets-1-0/website-home.webp differ diff --git a/layouts/_default/_markup/render-codeblock.html b/layouts/_default/_markup/render-codeblock.html index 043722680..cb4bde4ed 100644 --- a/layouts/_default/_markup/render-codeblock.html +++ b/layouts/_default/_markup/render-codeblock.html @@ -1,4 +1,6 @@ {{- $filename := .Attributes.filename -}} +{{- $shinylive := .Attributes.shinylive -}} +{{- $header := or $filename $shinylive -}} {{- $id := printf "code-filename-%d" .Ordinal -}} {{- $opts := .Options -}} {{- with .Page -}} @@ -6,9 +8,14 @@ {{- $opts = merge $opts (dict "linenos" true) -}} {{- end -}} {{- end -}} -
-{{- if $filename }} -
{{ $filename }}
+
+{{- if $header }} +
+ {{- with $filename }}{{ . }}{{ end -}} + {{- with $shinylive }} + Run in Shinylive + {{- end }} +
{{- end }} {{- highlight .Inner .Type $opts -}}
diff --git a/layouts/partials/item.html b/layouts/partials/item.html index ae7c0596e..117e9553b 100644 --- a/layouts/partials/item.html +++ b/layouts/partials/item.html @@ -521,7 +521,7 @@

{{ if and $hero_media.media $hero_image_show (not $nohero) }}
{{ if eq $hero_media.type "video" }} -