Skip to content

Add back the mime renderer JL extension #5096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 72 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5cb5754
Default to notebook connected mode
marthacryan Mar 17, 2025
e5e2994
Add back JL extension for mimerenderer ability
marthacryan Mar 18, 2025
583dea9
Use original code to maintain image load
marthacryan Mar 19, 2025
bed4c45
Move js into labextension directory
marthacryan Mar 20, 2025
1cd7c4f
update gitignore
marthacryan Mar 20, 2025
aa13a97
remove print statement
marthacryan Mar 20, 2025
23dad18
Update npm build to include jupyter lab extension build
marthacryan Mar 21, 2025
74724a5
Update paths and build for CI
marthacryan Mar 21, 2025
b8375f3
Replace pip with uv in plotly.js dev build CI
marthacryan Mar 21, 2025
df3970f
Update path to js in commands
marthacryan Mar 21, 2025
4353bba
Add labextension to additional package data
marthacryan Mar 21, 2025
ef5add1
Add labextension to additional package data
marthacryan Mar 21, 2025
14b5a0d
Fix CI
marthacryan Mar 27, 2025
af46e25
Change pin so that jupyterlab is >= 4
marthacryan Mar 28, 2025
5ced43e
Fix filepath in docs ci
marthacryan Mar 28, 2025
847b87c
Make extension compatible with jupyterlab 3 and 4
marthacryan Apr 4, 2025
00a794b
Merge branch 'main' of github.com:plotly/plotly.py into notebook-conn…
marthacryan Apr 4, 2025
61df8d7
Update test for slightly different value
marthacryan Apr 4, 2025
8f32ac5
Update test for slightly different value
marthacryan Apr 4, 2025
0ee60e7
Pin shapely version in test requirements
marthacryan Apr 4, 2025
4a2f699
Make default renderer in jupyterlab/notebook plotly_mimetype
marthacryan Apr 7, 2025
18f70ac
AUpdate file structure and make package include jupyterlab files
marthacryan Apr 11, 2025
ca54548
Update js access to use new filepaths
marthacryan Apr 11, 2025
b827f02
Update path of js output
marthacryan Apr 11, 2025
c67cada
Add metadata about jupyterlab extension
marthacryan Apr 11, 2025
e3afcf7
Add version into package
marthacryan Apr 11, 2025
62721e9
Add js build to dev build
marthacryan Apr 11, 2025
3a6f3ee
Revert changes to requirements
marthacryan Apr 11, 2025
0859aef
Merge branch 'main' of github.com:plotly/plotly.py into notebook-conn…
marthacryan Apr 11, 2025
1260612
Update node root path in commands.py
marthacryan Apr 11, 2025
1db6c81
Add js build to CI
marthacryan Apr 11, 2025
4bcbd30
Black
marthacryan Apr 11, 2025
b8cc069
Update build files included in output
marthacryan Apr 11, 2025
cbfddad
Add CI to check for changes to js build files
marthacryan Apr 11, 2025
5254258
Add build step to check for js build changes in CI
marthacryan Apr 11, 2025
f51b3dc
Add build file
marthacryan Apr 11, 2025
b4cd36c
Make js uncommitted files check its own job
marthacryan Apr 11, 2025
5d0aa9c
Make js uncommitted files check its own job
marthacryan Apr 11, 2025
56433a7
Add jupyter to env before running npm run build
marthacryan Apr 11, 2025
a7cf8e1
Commit built widget js
marthacryan Apr 11, 2025
54cc73f
Use tmp to compare the build files before and after build
marthacryan Apr 11, 2025
afc511a
Remove extra call to check js build job
marthacryan Apr 11, 2025
87c5260
Update diff and only run CI when there are changes in the js directory
marthacryan Apr 14, 2025
f167e6f
Attempt running CI
marthacryan Apr 14, 2025
daac60e
Try different approach to only running on changes to js/
marthacryan Apr 14, 2025
024325e
Add debugging statements to the diff checker
marthacryan Apr 14, 2025
0df9265
Add special handling for package.json
marthacryan Apr 14, 2025
e26d9da
Update ignore pattern
marthacryan Apr 14, 2025
ab922bf
Add debugging print statements
marthacryan Apr 14, 2025
a56c55a
update diff method
marthacryan Apr 14, 2025
f7df6a8
update diff method
marthacryan Apr 14, 2025
ce27281
Add artifact upload when ci finds differences between build and src
marthacryan Apr 14, 2025
f918835
Dummy commit to check CI
marthacryan Apr 14, 2025
cd26c8f
Use github actions instead of circleci for checking js build files
marthacryan Apr 15, 2025
585cf4a
fix syntax error
marthacryan Apr 15, 2025
4fdca55
Dummy js commit
marthacryan Apr 15, 2025
d7157f6
Fix artifact upload
marthacryan Apr 15, 2025
d10fd16
Update labextension source
marthacryan Apr 15, 2025
ce161d9
Update CONTRIBUTING.md
marthacryan Apr 15, 2025
48c510c
Add back npm build to full release build
marthacryan Apr 15, 2025
2dbb09c
Remove extraneous or true
marthacryan Apr 15, 2025
9e097ec
Update CONTRIBUTING.md
marthacryan Apr 15, 2025
f3a4278
Update logic for deciding whether js has changed
marthacryan Apr 15, 2025
5baedf3
Update name of CI step
marthacryan Apr 15, 2025
2e9a296
Update CONTRIBUTING.md
emilykl Apr 15, 2025
15ea2d7
Update .github/workflows/check-js-build.yml
marthacryan Apr 15, 2025
a4b0c42
Merge pull request #5144 from plotly/js-contributing-md-updates
marthacryan Apr 15, 2025
35506f3
remove check for changes in js folder to avoid missing CI failures
marthacryan Apr 15, 2025
ce867a1
Update node version in github actions
marthacryan Apr 15, 2025
8f3227e
remove extraneous persist_credentials flag
marthacryan Apr 15, 2025
3ac4224
Update version to match plotly.py version
marthacryan Apr 15, 2025
60735fe
Update build files
marthacryan Apr 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ commands:
source .venv/bin/activate
uv pip install .
uv pip install -r ./test_requirements/requirements_optional.txt
cd js
npm ci
npm run build

- when:
condition:
Expand Down Expand Up @@ -269,22 +266,18 @@ jobs:

steps:
- checkout

- run:
name: initial NPM Build
name: PyPI Build
command: |
python -m venv venv
. venv/bin/activate
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
source .venv/bin/activate
uv pip install build
uv pip install jupyter
cd js
npm ci
npm run build
git status

- run:
name: PyPI Build
command: |
. venv/bin/activate
pip install build
cd ..
python -m build --sdist --wheel -o dist
cp -R dist output
git status
Expand All @@ -310,7 +303,6 @@ jobs:
- checkout
- browser-tools/install-chrome
- browser-tools/install-chromedriver

- run:
name: Install dependencies
command: |
Expand All @@ -319,16 +311,11 @@ jobs:
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt
cd ..
if [ "${CIRCLE_BRANCH}" != "doc-prod" ]; then
uv pip uninstall plotly
cd ..
uv pip install -e .
cd js
npm ci
npm run build
cd ../doc
fi
cd ..

- run:
name: make html
Expand Down Expand Up @@ -420,7 +407,7 @@ workflows:
release_build:
jobs:
- full_build

build:
jobs:
- test_core_py:
Expand Down Expand Up @@ -449,4 +436,4 @@ workflows:
pandas_version: "1.2.4"
numpy_version: "1.26.4"
- python_311_percy
- build-doc
- build-doc
66 changes: 66 additions & 0 deletions .github/workflows/check-js-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
on: push

jobs:
check-js-build:
name: Check JS build artifacts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install Node
uses: actions/setup-node@v2
with:
node-version: '22'

- name: Copy current files to a temporary directory
run: |
cp -R plotly/labextension/ plotly/labextension-tmp/

- name: Install dependencies and build
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
source .venv/bin/activate
uv pip install jupyter
cd js
npm ci
npm run build
- name: Check JupyterLab build artifacts
run: |
# 1. Hash contents of all static files, sort by content hash
find plotly/labextension/static -type f -exec sha256sum {} \; | awk '{print $1}' | sort > new_hashes.txt
find plotly/labextension-tmp/static -type f -exec sha256sum {} \; | awk '{print $1}' | sort > old_hashes.txt

# 2. Compare the sorted content hashes
diff old_hashes.txt new_hashes.txt > content_diff.txt

# Remove the "load" line from both package.json files before comparing
grep -v '"load": "static/' plotly/labextension/package.json > pkg1.json
grep -v '"load": "static/' plotly/labextension-tmp/package.json > pkg2.json

# Compare stripped versions
diff pkg1.json pkg2.json > package_json_diff.txt

# 5. Final check
if [ -s content_diff.txt ] || [ -s package_json_diff.txt ]; then
echo "❌ Build artifacts differ:"
echo "--- Unexpected diffs ---"
cat content_diff.txt
echo "--- Unexpected package.json diffs ---"
cat package_json_diff.txt
echo "Please replace the 'plotly/labextension' directory with the artifacts of this CI run."
exit 1
else
echo "✅ Build artifacts match expected output (ignoring known 'load' hash in package.json)."
fi

- name: Store the build artifacts from plotly/labextension
uses: actions/upload-artifact@v4
if: failure()
with:
name: labextension
path: plotly/labextension
4 changes: 1 addition & 3 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -20,7 +18,7 @@ jobs:
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '22'

- name: Install npm dependencies
run: |
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ doc/python/.mapbox_token
doc/.ipynb_checkpoints
tags
doc/check-or-enforce-order.py
plotly/package_data/widgetbundle.js

tests/percy/*.html
tests/percy/pandas2/*.html
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ and
[`pip`](https://pip.pypa.io/en/stable/reference/pip_install/#install-editable)
documentation on _development mode_.

### Updating the `js/` directory
**This is only necessary if you're making changes to files in the `js/` directory.**
If you make changes to any files in the `js/` directory, you must run `npm install && npm run build` from the `js/` directory to rebuild the FigureWidget and JupyterLab extension.
You must then commit the build artifacts produced in `plotly/labextension`. A CI job will verify that this step has been done correctly.

**Notes on the contents of the `js/` directory:**
The `js/` directory contains Javascript code which helps with using Plotly in Jupyter notebooks.

There are two kinds of Jupyter support included in the `js/` directory:
1. **Mime Renderer JupyterLab extension**: This is the default renderer for Plotly `Figure()` objects in Jupyter notebooks. The Plotly mime renderer JupyterLab extension is used automatically by JupyterLab / Jupyter Notebook
when it sees the mimetype `application/vnd.plotly.v1+json` in the notebook output. The mime renderer loads `plotly.js` a single time and references it each time a Plotly figure is used in the notebook. This allows us to avoid embedding `plotly.js` in the notebook output. The JupyterLab extension source code is located at `js/src/mimeExtension.ts` and the compiled extension code is located at `plotly/labextension` in the built Python package. The command `jupyter labextension build` (which is one of the steps called by `npm run build`) compiles the extension and places the build artifacts in `plotly/labextension`.
2. **FigureWidget**: This is a more-interactive method for rendering Plotly charts in notebooks. FigureWidget used by creating a `FigureWidget()` object inside the notebook code (in place of a `Figure()`). It allows for communication between the Javascript frontend and Python backend, and requires the installation of an additional Python package (`anywidget`). The FigureWidget source code is located at `js/src/widget.ts`, and is included in the built Python package at `plotly/package_data/widgetbundle.js`.

### Configure black code formatting

This repo uses the [Black](https://black.readthedocs.io/en/stable/) code formatter,
Expand Down
9 changes: 9 additions & 0 deletions js/install.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"schemaVersion": 1,
"name": "jupyterlab-plotly",
"version": "6.0.1",
"jupyterlab": {
"mimeExtension": "lib/mimeExtension.js"
}
}

3,865 changes: 3,865 additions & 0 deletions js/lib/mimeExtension.js

Large diffs are not rendered by default.

Loading