You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the [Jupyter Widgets](https://shiny.rstudio.com/py/docs/ipywidgets.html) article on the Shiny for Python website for more details.
6
8
7
9
## Installation
8
10
9
11
```sh
10
12
pip install shinywidgets
11
13
```
12
14
13
-
## Overview
14
-
15
-
See the [using ipywidgets section](https://shiny.rstudio.com/py/docs/ipywidgets.html) of the Shiny for Python website.
16
-
17
-
## Frequently asked questions
18
-
19
-
### What ipywidgets are supported?
20
-
21
-
In theory, shinywidgets supports any instance that inherits from `{ipywidgets}`' `Widget` class. That is, if `isinstance(obj, ipywidgets.widgets.Widget)` returns `True` for some object `obj`, then `{shinywidgets}` should be able to render it.
22
-
23
-
`{shinywidgets}` can also render objects that don't inherit from `Widget`, but have a known way of coercing into a `Widget` instance. This list currently includes:
* Pydeck's `Deck` class (via it's `.show()` method).
28
-
* Bokeh widgets (via the [jupyter_bokeh](https://github.com/bokeh/jupyter_bokeh) package).
29
-
* Bokeh widgets are a bit of a special case, as they require some extra setup to work in Shiny. See the [Bokeh widgets aren't displaying, what gives?](#bokeh-widgets-arent-displaying-what-gives) section below for more details.
30
-
31
-
[See here](https://github.com/rstudio/py-shinywidgets/blob/main/shinywidgets/_as_widget.py) 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](https://github.com/rstudio/py-shinywidgets/issues/new).
32
-
33
-
### Bokeh setup
34
-
35
-
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:
36
-
37
-
```py
38
-
from shiny import ui
39
-
from shinywidgets import bokeh_dependencies
40
-
41
-
app_ui = ui.page_fluid(
42
-
bokeh_dependencies(),
43
-
# ...
44
-
)
45
-
```
46
-
47
-
48
-
### Does `{shinywidgets}` work with Shinylive?
49
-
50
-
To some extent, yes. As shown on the official [shinylive examples](https://shinylive.io/py/examples/), packages like plotly and ipyleaflet work (as long as you've provided the proper dependencies in a [`requirements.txt` file](https://shinylive.io/py/examples/#extra-packages)), 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.
51
-
52
-
### How do I size the widget?
53
-
54
-
`{ipywidgets}`' `Widget` class has [it's own API for setting inline CSS
including `height` and `width`. So, given a `Widget` instance `w`, you should be able to
57
-
do something like:
58
-
59
-
```py
60
-
w.layout.height ="100%"
61
-
w.layout.width ="100%"
62
-
```
63
-
64
-
### How do I hide/show a widget?
65
-
66
-
As mentioned above, a `Widget` class should have a `layout` attribute, which can be
67
-
used to set all sorts of CSS styles, including display and visibility. So, if you wanted
68
-
to hide a widget and still have space allocated for it:
69
-
70
-
```py
71
-
w.layout.visibility ="hidden"
72
-
```
73
-
74
-
Or, to not give it any space:
75
-
76
-
```py
77
-
w.layout.display ="none"
78
-
```
79
-
80
-
### Can I render widgets that contain other widgets?
81
-
82
-
Yes! In fact this a crucial aspect to how packages like `{ipyleaflet}` work. In
83
-
`{ipyleaflet}`'s case, each [individual marker is a widget](https://ipyleaflet.readthedocs.io/en/latest/layers/circle_marker.html) which gets attached to a `Map()` via `.add_layer()`.
84
-
85
-
## Troubleshooting
86
-
87
-
If after [installing](#installation)`{shinywidgets}`, you have trouble rendering widgets,
88
-
first try running the "hello world" ipywidgets [example](https://github.com/rstudio/py-shinywidgets/blob/main/examples/ipywidgets/app.py). If that doesn't work, it could be that you have an unsupported version
89
-
of a dependency like `{ipywidgets}` or `{shiny}`.
90
-
91
-
If you can run the "hello world" example, but "3rd party" widget(s) don't work, first
92
-
check that the extension is properly configured with `jupyter nbextension list`. Even if
93
-
the extension is properly configured, it still may not work right away, especially if
94
-
that widget requires initialization code in a notebook environment. In this case,
95
-
`{shinywidgets}` probably won't work without providing the equivalent setup information to
96
-
Shiny. A known case of this is bokeh, which is why shinywidgets includes a [`bokeh_dependency()` function](https://github.com/posit-dev/py-shinywidgets/blob/255a0d15d74828c28999cdce3fe9a0b5c2795016/examples/outputs/app.py#L26).
97
-
98
-
99
15
## Development
100
16
101
17
If you want to do development on `{shinywidgets}`, run:
0 commit comments