Skip to content

Commit 4d99b35

Browse files
authored
Merge pull request #4823 from plotly/anywidget
Switch to use anywidget
2 parents 972a59d + 6d3f0a7 commit 4d99b35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4086
-14368
lines changed

Diff for: .circleci/config.yml

+18-10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ commands:
4646
. venv/bin/activate
4747
pip install --upgrade pip wheel
4848
pip install -r ./test_requirements/requirements_<<parameters.py>>_optional.txt
49+
cd js
50+
npm ci
51+
npm run build
4952
- run:
5053
name: Install plotly-geo
5154
command: |
@@ -347,9 +350,9 @@ jobs:
347350
. venv/bin/activate
348351
pip install --upgrade pip wheel
349352
pip install -r ./test_requirements/requirements_38_core.txt black inflect
350-
pip install jupyterlab~=3.0
353+
pip install jupyterlab
351354
- run:
352-
name: Update jupyterlab-plotly version
355+
name: Update jupyter widget plotly.js version
353356
command: |
354357
cd packages/python/plotly
355358
. venv/bin/activate
@@ -403,7 +406,7 @@ jobs:
403406
conda config --remove channels defaults
404407
conda config --add channels conda-forge
405408
conda create -n env --yes python=3.9 conda-build=3.28.4 conda-verify
406-
conda install -n env -c conda-forge jupyterlab=3 nodejs=16
409+
conda install -n env -c conda-forge jupyterlab nodejs=16
407410
conda init bash
408411
mkdir output
409412
@@ -412,9 +415,9 @@ jobs:
412415
command: |
413416
eval "$(conda shell.bash hook)"
414417
conda activate env
415-
cd packages/javascript/jupyterlab-plotly
418+
cd packages/python/plotly/js
416419
npm ci
417-
npm run build:prod
420+
npm run build
418421
git status
419422
420423
- run:
@@ -438,13 +441,13 @@ jobs:
438441
git status
439442
440443
- run:
441-
name: NPM Pack
444+
name: Build Widget javascript bundle
442445
command: |
443446
eval "$(conda shell.bash hook)"
444447
conda activate env
445-
cd packages/javascript/jupyterlab-plotly
446-
npm pack
447-
mv jupyterlab-plotly*.tgz ../../../output
448+
cd packages/python/plotly/js
449+
npm ci
450+
npm run build
448451
449452
- run:
450453
name: Zip output
@@ -491,7 +494,12 @@ jobs:
491494
pip install -r requirements.txt
492495
if [ "${CIRCLE_BRANCH}" != "doc-prod" ]; then
493496
pip uninstall -y plotly
494-
pip install -e ../packages/python/plotly
497+
cd ../packages/python/plotly
498+
pip install -e .
499+
cd js
500+
npm ci
501+
npm run build
502+
cd ../../../../doc
495503
fi
496504
cd ..
497505
- run:

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ doc/check-or-enforce-order.py
5959
packages/javascript/jupyterlab-plotly/lib/
6060
packages/python/plotly/jupyterlab_plotly/labextension/
6161
packages/python/plotly/jupyterlab_plotly/nbextension/index.js*
62+
packages/python/plotly/plotly/package_data/widgetbundle.js
6263

6364
test/percy/*.html
6465
test/percy/pandas2/*.html

Diff for: README.md

+7-58
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@
3737
</a>
3838
</div>
3939

40-
4140
## Quickstart
4241

4342
`pip install plotly==5.24.1`
4443

45-
Inside [Jupyter](https://jupyter.org/install) (installable with `pip install "jupyterlab>=3" "ipywidgets>=7.6"`):
46-
4744
```python
4845
import plotly.express as px
4946
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
@@ -52,7 +49,6 @@ fig.show()
5249

5350
See the [Python documentation](https://plotly.com/python/) for more examples.
5451

55-
5652
## Overview
5753

5854
[plotly.py](https://plotly.com/python/) is an interactive, open-source, and browser-based graphing library for Python :sparkles:
@@ -82,7 +78,7 @@ Built on top of [plotly.js](https://github.com/plotly/plotly.js), `plotly.py` is
8278

8379
## Installation
8480

85-
plotly.py may be installed using pip...
81+
plotly.py may be installed using pip
8682

8783
```
8884
pip install plotly==5.24.1
@@ -94,43 +90,19 @@ or conda.
9490
conda install -c plotly plotly=5.24.1
9591
```
9692

97-
### JupyterLab Support
93+
### Jupyter Widget Support
9894

99-
For use in [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/), install the `jupyterlab` and `ipywidgets`
95+
For use as a Jupyter widget, install `jupyter` and `anywidget`
10096
packages using `pip`:
10197

10298
```
103-
pip install "jupyterlab>=3" "ipywidgets>=7.6"
99+
pip install jupyter anywidget
104100
```
105101

106102
or `conda`:
107103

108104
```
109-
conda install "jupyterlab>=3" "ipywidgets>=7.6"
110-
```
111-
112-
The instructions above apply to JupyterLab 3.x. **For JupyterLab 2 or earlier**, run the following commands to install the required JupyterLab extensions (note that this will require [`node`](https://nodejs.org/) to be installed):
113-
114-
```
115-
# JupyterLab 2.x renderer support
116-
jupyter labextension install [email protected] @jupyter-widgets/jupyterlab-manager
117-
```
118-
119-
Please check out our [Troubleshooting guide](https://plotly.com/python/troubleshooting/) if you run into any problems with JupyterLab.
120-
121-
### Jupyter Notebook Support
122-
123-
For use in the Jupyter Notebook, install the `notebook` and `ipywidgets`
124-
packages using `pip`:
125-
126-
```
127-
pip install "notebook>=5.3" "ipywidgets>=7.5"
128-
```
129-
130-
or `conda`:
131-
132-
```
133-
conda install "notebook>=5.3" "ipywidgets>=7.5"
105+
conda install jupyter anywidget
134106
```
135107

136108
### Static Image Export
@@ -143,41 +115,18 @@ command line utility (legacy as of `plotly` version 4.9).
143115
#### Kaleido
144116

145117
The [`kaleido`](https://github.com/plotly/Kaleido) package has no dependencies and can be installed
146-
using pip...
118+
using pip
147119

148120
```
149121
pip install -U kaleido
150122
```
151123

152-
or conda.
124+
or conda
153125

154126
```
155127
conda install -c conda-forge python-kaleido
156128
```
157129

158-
#### Orca
159-
160-
While Kaleido is now the recommended image export approach because it is easier to install
161-
and more widely compatible, [static image export](https://plotly.com/python/static-image-export/)
162-
can also be supported
163-
by the legacy [orca](https://github.com/plotly/orca) command line utility and the
164-
[`psutil`](https://github.com/giampaolo/psutil) Python package.
165-
166-
These dependencies can both be installed using conda:
167-
168-
```
169-
conda install -c plotly plotly-orca==1.3.1 psutil
170-
```
171-
172-
Or, `psutil` can be installed using pip...
173-
174-
```
175-
pip install psutil
176-
```
177-
178-
and orca can be installed according to the instructions in the [orca README](https://github.com/plotly/orca).
179-
180-
181130
### Extended Geo Support
182131

183132
Some plotly.py features rely on fairly large geographic shape files. The county

Diff for: contributing.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ complete installation and avoid gdal-config errors.
157157
(plotly_dev) $ pip install -e packages/python/chart-studio/
158158
(plotly_dev) $ pip install -e packages/python/plotly-geo/
159159
```
160-
This will ensure that the installed packages links to your local development
160+
161+
**Note**: To test `go.FigureWidget` locally, you'll need to generate the javascript bundle as follows:
162+
```
163+
cd packages/python/plotly/js
164+
npm install && npm run build
165+
```
166+
167+
Running `pip install -e` will ensure that the installed packages links to your local development
161168
directory, meaning that all changes you make reflect directly in your
162169
environment (don't forget to restart the Jupyter kernel though!). For more
163170
information see the
@@ -211,7 +218,7 @@ make that pull request!
211218

212219

213220
## Update to a new version of Plotly.js
214-
First update the version of the `plotly.js` dependency in `packages/javascript/jupyterlab-plotly/package.json`.
221+
First update the version of the `plotly.js` dependency in `packages/python/plotly/js/package.json`.
215222

216223
Then run the `updateplotlyjs` command with:
217224

Diff for: doc/python/getting-started.md

+3-12
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,16 @@ IFrame(snippet_url + 'getting-started', width='100%', height=1200)
9696

9797
#### JupyterLab Support
9898

99-
To use `plotly` in [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/), install the `jupyterlab` and `ipywidgets` packages in the same environment as you installed `plotly`, using `pip`:
99+
To use `plotly` in [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/), install the `jupyterlab` and `anywidget` packages in the same environment as you installed `plotly`, using `pip`:
100100

101101
```
102-
$ pip install "jupyterlab>=3" "ipywidgets>=7.6"
102+
$ pip install jupyterlab anywidget
103103
```
104104

105105
or `conda`:
106106

107107
```
108-
$ conda install "jupyterlab>=3" "ipywidgets>=7.6"
109-
```
110-
111-
The `plotly` jupyterlab extension is included when you install `plotly` using `pip` or `conda`. When you run Jupyter Lab, ensure you are running it in the same environment that you installed `plotly` in so it has access to the `plotly` jupyterlab extension.
112-
113-
**JupyterLab 2 or earlier** does not support the prebuilt extensions installed using `pip` and `conda`. If you are using JupyterLab 2, run the following command to install the required JupyterLab extensions (note that this will require [`node`](https://nodejs.org/) to be installed):
114-
115-
```
116-
# JupyterLab 2.x renderer support
117-
jupyter labextension install [email protected] @jupyter-widgets/jupyterlab-manager
108+
$ conda install jupyterlab anywidget
118109
```
119110

120111
Launch JupyterLab with:

Diff for: doc/python/troubleshooting.md

-81
Original file line numberDiff line numberDiff line change
@@ -68,87 +68,6 @@ IFrame(snippet_url + 'renderers', width='100%', height=1200)
6868
<div style="font-size: 0.9em;"><div style="width: calc(100% - 30px); box-shadow: none; border: thin solid rgb(229, 229, 229);"><div style="padding: 5px;"><div><p><strong>Sign up for Dash Club</strong> → Free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture.
6969
<u><a href="https://go.plotly.com/dash-club?utm_source=Dash+Club+2022&utm_medium=graphing_libraries&utm_content=inline">Join now</a></u>.</p></div></div></div></div>
7070

71-
<!-- #region -->
72-
### JupyterLab Problems
73-
74-
In order to use `plotly` in JupyterLab, you *must have the `jupyterlab-plotly` extension installed* as detailed in the [Getting Started guide](/python/getting-started). When you install `plotly`, this extension is automatically made available to any JupyterLab 3.x installation in the same Python environment.
75-
76-
To list your current extensions, run the following command in a terminal shell **from the same environment as JupyterLab is launched**:
77-
78-
```bash
79-
# Check that jupyterlab-plotly is installed
80-
$ jupyter labextension list
81-
```
82-
83-
Please note that the *extension version matters*: the extension versions in the [Getting Started](/python/getting-started) guide match the version of `plotly` at the top of the guide and so they should be installed together. Note also that these extensions are meant to work with JupyterLab 1 or above but not 0.x.
84-
85-
If automatic installation of the extension is not working in your environment, or if you are using JupyterLab 1.x or 2.0, you may install it manually using the following command, which requires `node` to be installed.
86-
87-
```bash
88-
# Manually reinstall the extension
89-
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyterlab-plotly
90-
```
91-
92-
If you have [installed additional python environments](https://ipython.readthedocs.io/en/stable/install/kernel_install.html) (or kernels) to use with JupyterLab, or if you are using a centrally hosted JupyterLab installation, you need to make sure that the extensions are installed in the python environment used to launch JupyterLab (the "server" environment). If you accidentally installed the extensions (and run the command above) in one of the additional python environments ("processing" environments), then it is possible for the command above to list the correct extensions but for them to not be available in the JupyterLab front-end you have loaded in your browser. To check if this is the problem, you can [look at the active extension list through your browser via the JupyterLab Extension Manager](https://jupyterlab.readthedocs.io/en/stable/user/extensions.html#using-the-extension-manager), which will always list the extensions in the "server" environment. To summarize: if you use JupyterLab with multiple python environments, the extensions must be installed in the "server" environment, and the plotly python library must be installed in each "processing" environment that you intend to use.
93-
94-
> Note that version 4.14.3 of `plotly` or earlier needed two extensions (`jupyterlab-plotly` and `plotlywidget`) to be installed manually running, and that `plotlywidget` requires `@jupyter-widgets/jupyterlab-manager` to be installed:
95-
96-
```bash
97-
# Instructions for `plotly` 4.x
98-
$ jupyter labextension install jupyterlab-plotly plotlywidget @jupyter-widgets/jupyterlab-manager
99-
```
100-
101-
If you have the correct version(s) of the extension(s) installed and active in your active JupyterLab sessions and are still seeing problems, the issue may clear up if you rebuild JupyterLab. This shouldn't be required in principle but some users have resolved their issues this way. To rebuild JupyterLab, shut down JupyterLab and run the following command in a terminal shell **from the same environment as JupyterLab was launched**:
102-
103-
```bash
104-
# rebuilding JupyterLab
105-
$ jupyter lab build
106-
```
107-
108-
To uninstall your Plotly extensions prior to reinstalling them, run the following commands in a terminal shell before reinstalling them by following the instructions in the [Getting Started guide](/python/getting-started):
109-
110-
```bash
111-
# uninstalling extensions to reinstall
112-
$ jupyter labextension uninstall jupyterlab-plotly
113-
$ jupyter labextension uninstall plotlywidget
114-
```
115-
116-
If you run into "out of memory" problems while installing the extensions or building JupyterLab, try running these commands before running `jupyter labextension install`...
117-
118-
```bash
119-
# Avoid "JavaScript heap out of memory" errors during extension installation
120-
# (OS X/Linux)
121-
export NODE_OPTIONS=--max-old-space-size=4096
122-
# (Windows)
123-
set NODE_OPTIONS=--max-old-space-size=4096
124-
```
125-
126-
...and these commands afterwards.
127-
128-
```bash
129-
# Unset NODE_OPTIONS environment variable
130-
# (OS X/Linux)
131-
unset NODE_OPTIONS
132-
# (Windows)
133-
set NODE_OPTIONS=
134-
```
135-
136-
### Jupyter Classic Notebook Problems
137-
138-
The classic Jupyter Notebook (i.e. launched with `jupyter notebook`) sometimes suffers from a problem whereby if you close the window and reopen it, your plots render as blank spaces.
139-
140-
The easiest solution is to force the `notebook` renderer to reload by calling `fig.show("notebook")` instead of just `fig.show()`.
141-
142-
If this problem is recurrent, you may safely run the following code in a Notebook (not in JupyterLab!) at any time and it should restore your figures (for example, you may put it at the top of your notebook for easy access):
143-
144-
```python
145-
import plotly.io as pio
146-
pio.renderers.default='notebook'
147-
```
148-
149-
As a last resort, you can "Restart & Clear Output" from the Kernel menu and rerun your notebook.
150-
151-
<!-- #endregion -->
15271

15372
### VSCode Notebook, Nteract and Streamlit Problems
15473

Diff for: doc/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
plotly==5.24.1
22
jupytext==1.16.4
3-
ipywidgets==7.7.2
43
jupyter-client<7
54
jupyter
65
notebook
@@ -46,3 +45,4 @@ dask==2022.2.0
4645
polars
4746
geoparse<=2.0.3
4847
xarray==2022.9.0
48+
anywidget

Diff for: packages/javascript/jupyterlab-plotly/README.md

-6
This file was deleted.

0 commit comments

Comments
 (0)