Shiny for Python
New course: Since the recording, we've partnered with Posit and the Shiny team to launch a free course on Shiny named Reactive Web Dashboards with Shiny. If this episode inspires you, please check out the course.
Episode Deep Dive
Guests introduction and background
Joe Cheng is the Chief Technology Officer (CTO) at Posit (formerly RStudio). He has an extensive background in web development, originally working on both front-end and backend projects as well as desktop applications. Joe was one of the first employees at RStudio, co-creating the RStudio IDE and eventually leading the development of Shiny, a framework for building interactive apps in R. With the recent release of Shiny for Python, he’s focused on bringing its reactive programming model to the Python ecosystem.
What to Know If You're New to Python
Here are a few points to help new Python developers get more out of this episode:
- Understand how to install and run third-party libraries (e.g.,
pip install shiny
), so you can experiment with Shiny for Python. - Know the basics of Python functions and decorators, as Shiny for Python uses decorators to indicate reactive outputs.
- Grasp the idea of web app frameworks (e.g., Flask, FastAPI) even at a high level; Shiny for Python is built on Starlette and can run on an ASGI server.
- Official Shiny for Python Docs: The main place to go for installation steps, tutorials, and reference material.
Key points and takeaways
- Shiny for Python: A Reactive Framework for Data Science Shiny for Python brings a powerful reactive engine to the Python community. It automatically manages relationships between inputs and outputs, so that your application’s elements update themselves with minimal effort. This bridges the gap between data exploration and data communication, allowing data scientists to share interactive web apps without writing low-level JavaScript or handling complicated state management manually.
- Links and tools:
- Reactive Programming vs. Event-Driven Callbacks Traditional Python web frameworks often rely on callbacks and manual event handling, which can become cumbersome. Shiny’s reactive model tracks dependencies between variables and outputs, automatically invalidating and recomputing them only when necessary. This eliminates a lot of boilerplate and significantly reduces the chance of missing a crucial update.
- Streamlit Comparison Streamlit has a top-to-bottom execution model, making it very straightforward for small, quick prototypes. Joe highlighted that Shiny for Python aims to handle more sophisticated applications at scale by relying on its mature reactive engine. While Streamlit and Shiny both serve data science interactivity, Shiny’s design can better accommodate larger, more complex dashboards and multi-user scenarios.
- Links and tools:
- Evolution from Shiny for R to Shiny for Python The Shiny framework was originally built for R and has a massive community and ecosystem. With RStudio’s pivot to Posit and the release of Shiny for Python, many of the same concepts—like reactivity, shared state, and easy UI building—are now available in Python. R users and Python users alike can benefit from a common reactive approach to data-driven web apps.
- Links and tools:
- Deployment Options and Hosting Shiny for Python can be deployed on a variety of infrastructures, from local servers to cloud VMs and container platforms. It also has integrations with Posit Connect for enterprise-level deployments, including load balancing, authentication, and scaling. Additionally, Hugging Face Spaces was mentioned as a quick option for demos.
- Links and tools:
- Shared vs. Separate Session State Each user session in Shiny for Python typically holds its own state—ensuring that multiple users don’t overwrite each other’s interactions. However, Joe mentioned that Shiny can optionally allow shared state across sessions if you want to create collaborative or real-time apps where one user’s updates are reflected for everyone.
- Tools:
- Shiny’s session-scoped variables (built in)
- Tools:
- Async Capabilities Shiny for Python is built on asyncio. You don’t need to be an expert in asynchronous code to use it, but you can take advantage of asyncio to perform non-blocking I/O work or parallelize tasks across multiple user sessions. This means your apps can stay responsive even under heavier loads.
- Links and tools:
- UI Components and Plotting Libraries Shiny for Python supports a variety of Python data-visualization tools. In the discussion, Joe highlighted support for matplotlib and Plotly, along with IPyWidgets for deeper interaction. Future updates will include more built-in UI and layout components, making it easier to build dashboard-like applications.
- Links and tools:
- Bridging Organizational Gaps between R and Python Organizations often have teams that use R and others that use Python. Shiny for Python fills this gap, letting Python-focused data scientists adopt the same interactive approach that’s been so successful in R. This unifies best practices under one umbrella, avoiding drastically different dashboards or reimplementations across languages.
- Tools:
- Roadmap: More UI and Testing Tools Joe shared plans to improve table rendering, expand Shiny for Python’s dashboard templates, and introduce a dedicated testing framework using Playwright. Over time, the UI and layout engine will evolve, but the reactive core will remain at the heart of the framework’s philosophy.
- Links and tools:
Interesting quotes and stories
- Discovering Reactive Programming: Joe described first seeing reactive programming in the JavaScript framework Meteor. He downloaded the source before a flight and by the time he landed, he had reverse-engineered how Meteor’s reactivity worked—sparking the idea that ultimately led to Shiny.
- Impactful Use Cases: Joe shared how Shiny has helped organizations—from universities tracking infectious diseases to businesses analyzing marketing data—bridge the gap between raw analysis and accessible, interactive dashboards that inform decision-making.
Key definitions and terms
- Reactive Programming: A paradigm that automatically propagates data changes across the application, ensuring outputs update whenever their input changes, without manual event wiring.
- Session State: The collection of data kept by the application on a per-user (or per-connection) basis, so that interactions remain distinct.
- Async / asyncio: Python’s asynchronous framework, allowing for non-blocking operations and concurrency within a single threaded event loop.
Learning resources
Below are a few suggested ways to dive deeper into Shiny and Python-driven dashboards:
- Reactive Web Dashboards with Shiny: A free and comprehensive course on building data-centric, reactive web apps in Python with Shiny.
- Shiny for Python Docs: Official reference for installation, usage patterns, examples, and advanced features.
Overall takeaway
Shiny for Python represents a significant leap in building interactive dashboards and data apps for Python users, giving them access to a proven reactive architecture previously available mainly to R developers. Whether you’re just prototyping or rolling out enterprise-grade data tools, Shiny’s model aims to simplify state management, minimize manual callbacks, and let you focus on the core data science logic.
Links from the show
Shiny: shiny.posit.co
Shiny for Python code: github.com
Discord community for Shiny: discord.gg
Reactive programming inside Shiny: shiny.posit.co
Shiny Gallery: shiny.posit.co
Examples: shiny.posit.co
Orbital mechanics in Shiny: shiny.posit.co
Wordle in Shiny: shiny.posit.co
Keynote introducing Shiny for Python: youtube.com
Talk Python's free Shiny course: talkpython.fm/shiny
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy