Shiny
Shiny is an open-source web development framework for Python, enabling data scientists and developers to build interactive web applications and dashboards with purely Python code. Maintained by Posit, it is under active development with frequent releases that introduce features like OpenTelemetry integration, toast notifications, AI-powered test generation, and application bookmarking. It allows for the creation of rich user interfaces that react dynamically to user input.
Common errors
-
Error: An error has occurred. Check your logs or contact the app author for clarification.
cause This is Shiny's default sanitized error message for deployed applications, hiding the underlying Python exception for security reasons.fixRun the application locally (`shiny run app.py --reload`) to see the full stack trace, or disable error sanitization in the `App` constructor: `app = App(app_ui, server, sanitize_errors=False)`. -
Output not appearing (e.g., a blank space where a plot or text should be) or 'Missing output' message.
cause The output function (`@render.text`, `@render.plot`, etc.) is trying to access an input ID that does not exist or is misspelled. Alternatively, there might be a runtime error within the render function.fixVerify that the `id` argument in `ui.output_*` matches the name of the decorated function in `server`. Ensure that `input.some_id()` refers to an existing `ui.input_some_id` component. Check the console for any Python exceptions or tracebacks. -
TypeError: 'ReactiveValue' object is not callable
cause Attempting to access a reactive value (like `input.some_id`) without calling it as a function (`input.some_id()`) within a reactive context.fixAlways append `()` when reading the value of an `input` or `reactive.value` within `@reactive.effect`, `@render.*`, or `@reactive.calc` functions, e.g., `input.slider_val()` instead of `input.slider_val`.
Warnings
- breaking Breaking changes in `shiny.playwright.controllers` for testing. `.expect_inverse()` now requires a `bool` (use `False` for previous behavior). `.expect_layout()` was renamed to `.expect_fluid()` and also requires a `bool` (use `True` for previous behavior).
- deprecated The `ui.Chat().set_user_message()` method has been deprecated.
- gotcha Shiny applications, by default, sanitize error messages when deployed to prevent sensitive information leakage. This can make debugging deployed applications challenging.
- gotcha Starting with v1.6.0, Shiny includes OpenTelemetry integration. The `SHINY_OTEL_COLLECT` environment variable controls the default collection level (e.g., 'none', 'session'). If not explicitly set, 'session' level telemetry might be collected.
- gotcha If an output in a Shiny app fails to render or shows a 'Missing output' error, it's often due to an attempt to read a non-existent input ID or an error within the `@render` function.
Install
-
pip install shiny
Imports
- App
from shiny import App
- ui
from shiny import ui
- render
from shiny import render
- reactive
from shiny import reactive
- input
from shiny import input
from shiny.express import input
- output
from shiny import output
from shiny.express import output
- session
from shiny import session
from shiny.express import session
Quickstart
from shiny import App, ui, render
app_ui = ui.page_fluid(
ui.input_slider("n", "N", 0, 100, 20),
ui.output_text_verbatim("txt"),
)
def server(input, output, session):
@render.text
def txt():
return f"The value of N is {input.n()}"
app = App(app_ui, server)