Skip to content

Commit

Permalink
Allow adding ipywidgets to extension in JupyterLab (#3392)
Browse files Browse the repository at this point in the history
* Allow adding ipywidgets to extension in JupyterLab

* Add ipywidgets to extension

* Update requirements

* Load ipywidgets ext for mpl example
  • Loading branch information
philippjfr authored Apr 15, 2022
1 parent 201c075 commit d40d87e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
conda install "pip<21.2.1"
conda list
doit develop_install -o doc -o examples
pip install pyecharts idom==0.24 ipympl
pip install pyecharts idom==0.24
- name: temporarily pin jinja2
run: |
eval "$(conda shell.bash hook)"
Expand Down
8 changes: 2 additions & 6 deletions examples/reference/panes/IPyWidget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
"import panel as pn\n",
"import ipywidgets as ipw\n",
"\n",
"pn.extension()"
"pn.extension('ipywidgets')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ``IPyWidget`` pane renders any ipywidgets model both in the notebook and in a deployed server. This makes it possible to leverage this growing ecosystem directly from within Panel simply by wrapping the component in a Pane or Panel. However when rendering ipywidgets on the server you may have to initialize the `ipywidgets` extension by running:\n",
"\n",
"```python\n",
"pn.extension('ipywidgets')\n",
"```\n",
"The ``IPyWidget`` pane renders any ipywidgets model both in the notebook and in a deployed server. This makes it possible to leverage this growing ecosystem directly from within Panel simply by wrapping the component in a Pane or Panel.\n",
"\n",
"In the notebook this is not necessary since Panel simply uses the regular notebook ipywidget renderer. Particularly in JupyterLab importing the ipywidgets extension in this way may interfere with the UI and render the JupyterLab UI unusable, so enable the extension with care.\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/reference/panes/Matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import panel as pn\n",
"\n",
"pn.extension()"
"pn.extension('ipywidgets')"
]
},
{
Expand Down
6 changes: 6 additions & 0 deletions panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ def __call__(self, *args, **params):
}
for arg in args:
if arg in self._imports:
try:
if (arg == 'ipywidgets' and get_ipython() and
not "PANEL_IPYWIDGET" in os.environ): # noqa (get_ipython)
continue
except Exception:
pass
__import__(self._imports[arg])
elif arg in reactive_exts:
ReactiveHTMLMetaclass._loaded_extensions.add(arg)
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ def run(self):
'ipywidgets_bokeh',
'ipyvolume',
'ipyleaflet',
'ipympl',
'folium',
'xarray',
'pyinstrument >=4.0',
'aiohttp',
'croniter',
'graphviz',
'networkx>=2.5',
'networkx >=2.5',
'pygraphviz'
],
'tests': _tests,
Expand Down

0 comments on commit d40d87e

Please sign in to comment.