shinywidgets
Render ipywidgets inside a Shiny app.
Installation
pip install shinywidgets
Overview
See the using ipywidgets section of the Shiny for Python website.
Frequently asked questions
What ipywidgets are supported?
In theory, shinywidgets supports any instance that inherits from {ipywidgets}' Widget class.
That said, {shinywidgets} can also "directly" render objects that don't inherit from Widget, but have a known way of coercing into a Widget instance. This list currently includes:
- Altair charts (via the vega package).
- Bokeh widgets (via the jupyter_bokeh package).
- Plotly's
Figureclass (viaFigureWidget). - Pydeck's
Deckclass (via it's.show()method).
See here for more details on how these objects are coerced into Widget instances, and if you know of other packages that should be added to this list, please let us know
Bokeh widgets aren't displaying, what gives?
Similar to how you have to run bokeh.io.output_notebook() to run {bokeh} in notebook, you also have to explicitly bring the JS/CSS dependencies to the Shiny app, which can be done this way:
from shiny import ui
from shinywidgets import bokeh_dependencies
app_ui = ui.page_fluid(
bokeh_dependencies(),
# ...
)
Does {shinywidgets} work with Shinylive?
To some extent, yes. As shown on the official shinylive examples, packages like plotly and ipyleaflet work (as long as you've provided the proper dependencies in a requirements.txt file), but other packages like altair and qgrid may not work (at least currently) due to missing wheel files and/or dependencies with compiled code that can't be compiled to WebAssembly.
How do I size the widget?
{ipywidgets}' Widget class has it's own API for setting inline CSS
styles,
including height and width. So, given a Widget instance w, you should be able to
do something like:
w.layout.height = "100%"
w.layout.width = "100%"
How do I hide/show a widget?
As mentioned above, a Widget class should have a layout attribute, which can be
used to set all sorts of CSS styles, including display and visibility. So, if you wanted
to hide a widget and still have space allocated for it:
w.layout.visibility = "hidden"
Or, to not give it any space:
w.layout.display = "none"
Can I render widgets that contain other widgets?
Yes! In fact this a crucial aspect to how packages like {ipyleaflet} work. In
{ipyleaflet}'s case, each individual marker is a widget which gets attached to a Map() via .add_layer().
Troubleshooting
If after installing {shinywidgets}, you have trouble rendering widgets,
first try running the "hello world" ipywidgets example. If that doesn't work, it could be that you have an unsupported version
of a dependency like {ipywidgets} or {shiny}.
If you can run the "hello world" example, but "3rd party" widget(s) don't work, first
check that the extension is properly configured with jupyter nbextension list. Even if
the extension is properly configured, it still may not work right away, especially if
that widget requires initialization code in a notebook environment. In this case,
{shinywidgets} probably won't work without providing the equivalent setup information to
Shiny. Some known cases of this are:
bokeh
To use {bokeh} in notebook, you have to run bokeh.io.output_notebook(). The
equivalent thing in Shiny is to include the following in the UI definition:
from shiny import ui
from shinywidgets import bokeh_dependencies
app_ui = ui.page_fluid(
bokeh_dependencies(),
# ...
)
Other widgets?
Know of another widget that requires initialization code? Please let us know about it!
Development
If you want to do development on {shinywidgets}, run:
pip install -e ".[dev,test]"
cd js && yarn watch
Metadata
Release files for shinywidgets 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shinywidgets-0.2.1.tar.gz | 1.8 MB | Without provenance | Details for shinywidgets-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shinywidgets-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for shinywidgets-0.2.1-py3-none-any.whl |
Total release size: 3.6 MB
Release files / shinywidgets-0.2.1.tar.gz
| Download URL | shinywidgets-0.2.1.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27c11bfd5f42c955156b2ef1780967947e51a606a9a7d75ce16daf595039719d
|
|
BLAKE2b-256 checksum How to use checksums |
7cb90c4f0ac578d4fc1b55035bccdfb0f30220003e53329c724c628fdb430950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / shinywidgets-0.2.1-py3-none-any.whl
| Download URL | shinywidgets-0.2.1-py3-none-any.whl |
|---|---|
| Size | 1.8 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7867d656d0cc82dac27ba89553850e574e7c250f4255ca2c92d23585d3324184
|
|
BLAKE2b-256 checksum How to use checksums |
1575fa60cba3521138f9940b2e0aa72faaf7c5c9c057dcd66b068f16ff7d0333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for shinywidgets 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.