Shiny Widgets Integration

0.8.0 · active · verified Fri Apr 17

shinywidgets facilitates the rendering and interactive use of `ipywidgets` within `Shiny for Python` applications. It bridges the gap between the rich interactive capabilities of `ipywidgets` and the reactive framework of Shiny, allowing users to embed existing widget ecosystems like `ipyleaflet`, `plotly.graph_objects.FigureWidget`, and `ipyvolume` directly into their Shiny apps. The current version is 0.8.0, with a fairly active release cadence, often addressing compatibility with new versions of `ipywidgets`, `plotly`, and `websockets`.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate an `ipywidgets.IntSlider` into a Shiny application. The `output_widget` function creates a placeholder in the UI, and the `@render_widget` decorator on the server side defines the `ipywidget` to be rendered. The widget's value can be accessed via `input.widget_id()` just like standard Shiny inputs.

from shiny import App, ui, render
from shinywidgets import output_widget, render_widget
import ipywidgets as widgets

app_ui = ui.page_fluid(
    ui.h2('Shiny + ipywidgets'),
    output_widget('my_slider'),
    ui.output_text('slider_value'),
)

def server(input, output, session):
    @render_widget
    def my_slider():
        return widgets.IntSlider(min=0, max=100, value=50, description='Slider:')

    @output
    @render.text
    def slider_value():
        return f'Slider value: {input.my_slider()}'

app = App(app_ui, server)

view raw JSON →