{"id":10226,"library":"shinywidgets","title":"Shiny Widgets Integration","description":"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`.","status":"active","version":"0.8.0","language":"en","source_language":"en","source_url":"https://github.com/rstudio/py-shinywidgets/","tags":["shiny","ipywidgets","web-development","dashboard","interactivity","widgets","rstudio"],"install":[{"cmd":"pip install shinywidgets","lang":"bash","label":"Install core library"},{"cmd":"pip install shinywidgets ipywidgets ipyleaflet","lang":"bash","label":"Install with common dependencies (e.g., ipyleaflet)"}],"dependencies":[{"reason":"Core framework for building applications.","package":"shiny","optional":false},{"reason":"The underlying interactive widget framework.","package":"ipywidgets","optional":false},{"reason":"Required for `altair` and `plotly` integrations since `shinywidgets` v0.5.0.","package":"anywidget","optional":true}],"imports":[{"symbol":"output_widget","correct":"from shinywidgets import output_widget"},{"symbol":"render_widget","correct":"from shinywidgets import render_widget"}],"quickstart":{"code":"from shiny import App, ui, render\nfrom shinywidgets import output_widget, render_widget\nimport ipywidgets as widgets\n\napp_ui = ui.page_fluid(\n    ui.h2('Shiny + ipywidgets'),\n    output_widget('my_slider'),\n    ui.output_text('slider_value'),\n)\n\ndef server(input, output, session):\n    @render_widget\n    def my_slider():\n        return widgets.IntSlider(min=0, max=100, value=50, description='Slider:')\n\n    @output\n    @render.text\n    def slider_value():\n        return f'Slider value: {input.my_slider()}'\n\napp = App(app_ui, server)","lang":"python","description":"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."},"warnings":[{"fix":"If automatic cleanup is required, consider re-evaluating widget initialization placement or explicitly managing the widget's lifecycle with `widget.close()` within the effect.","message":"Widgets initialized inside a `reactive.effect()` are no longer automatically removed when the effect invalidates. This change requires manual management of widget lifecycle if automatic cleanup was previously relied upon.","severity":"gotcha","affected_versions":">=0.6.0"},{"fix":"Ensure you `pip install anywidget` and, if using Plotly, `pip install plotly>=6.0.0`.","message":"For `altair` and `plotly` integrations, `anywidget` is now a direct dependency and must be installed separately. Additionally, `plotly` versions prior to 6.0.0 might be incompatible.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Upgrade `shinywidgets` to version `0.7.1` or newer (`pip install --upgrade shinywidgets`).","message":"`anywidget`-based widgets (e.g., Plotly, Altair) may fail to initialize or update correctly with `websockets` versions 16.0 or higher due to a fix introduced in `shinywidgets` v0.7.1.","severity":"gotcha","affected_versions":"<0.7.1"},{"fix":"Upgrade `shinywidgets` to version `0.7.2` or newer (`pip install --upgrade shinywidgets`) to ensure proper widget cleanup.","message":"In `shinywidgets` versions before 0.7.2, widget cleanup might not occur correctly if the widget was created inside a render output's context that differs from the current context, potentially leading to resource leaks or unexpected behavior.","severity":"gotcha","affected_versions":"<0.7.2"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Upgrade `shinywidgets` to version `0.5.1` or higher: `pip install --upgrade shinywidgets`.","cause":"This error occurred in `shinywidgets` versions prior to 0.5.1 due to an internal handling issue with widget representation, particularly with certain `ipywidgets`.","error":"AttributeError: object has no attribute '_repr_mimebundle_'"},{"fix":"Ensure `pip install anywidget plotly>=6.0.0` and `pip install --upgrade shinywidgets` (to at least v0.7.1) are executed.","cause":"Common causes include missing `anywidget` dependency, an outdated `plotly` version (pre-6.0.0), or incompatibility with `websockets>=16.0` in `shinywidgets < 0.7.1`.","error":"Plotly graph not rendering or failing to update in Shiny app."},{"fix":"Upgrade `shinywidgets` to version `0.5.0` or higher: `pip install --upgrade shinywidgets`.","cause":"This issue was specific to `ipyleaflet` integration in `shinywidgets` versions prior to 0.5.0, related to how closed widget objects were handled.","error":"ipyleaflet erroring out when attempting to read the .model_id property of a closed widget object."}]}