From d40d87e28a151f65733a5c338e2426e5056a5e72 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Fri, 15 Apr 2022 15:50:49 +0200 Subject: [PATCH] Allow adding ipywidgets to extension in JupyterLab (#3392) * Allow adding ipywidgets to extension in JupyterLab * Add ipywidgets to extension * Update requirements * Load ipywidgets ext for mpl example --- .github/workflows/docs.yaml | 2 +- examples/reference/panes/IPyWidget.ipynb | 8 ++------ examples/reference/panes/Matplotlib.ipynb | 2 +- panel/config.py | 6 ++++++ setup.py | 4 +++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index fb19fdc54f..f8aabde832 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -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)" diff --git a/examples/reference/panes/IPyWidget.ipynb b/examples/reference/panes/IPyWidget.ipynb index a884edfc7d..3c41b5e91a 100644 --- a/examples/reference/panes/IPyWidget.ipynb +++ b/examples/reference/panes/IPyWidget.ipynb @@ -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", diff --git a/examples/reference/panes/Matplotlib.ipynb b/examples/reference/panes/Matplotlib.ipynb index b2ca992965..40fb7f7331 100644 --- a/examples/reference/panes/Matplotlib.ipynb +++ b/examples/reference/panes/Matplotlib.ipynb @@ -8,7 +8,7 @@ "source": [ "import panel as pn\n", "\n", - "pn.extension()" + "pn.extension('ipywidgets')" ] }, { diff --git a/panel/config.py b/panel/config.py index 9666317302..98accf9677 100644 --- a/panel/config.py +++ b/panel/config.py @@ -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) diff --git a/setup.py b/setup.py index f9510d77b8..12a3d22445 100644 --- a/setup.py +++ b/setup.py @@ -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,