Skip to content
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

Add back the mime renderer JL extension #5096

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 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
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
22 changes: 12 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ commands:
source .venv/bin/activate
uv pip install .
uv pip install -r ./test_requirements/requirements_optional.txt
cd js
cd plotly/labextension
npm ci
npm run build

Expand Down Expand Up @@ -273,18 +273,20 @@ jobs:
- run:
name: initial NPM Build
command: |
python -m venv venv
. venv/bin/activate
cd js
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
source .venv/bin/activate
uv pip install jupyter
cd plotly/labextension
npm ci
npm run build
git status

- run:
name: PyPI Build
command: |
. venv/bin/activate
pip install build
source .venv/bin/activate
uv pip install build
python -m build --sdist --wheel -o dist
cp -R dist output
git status
Expand Down Expand Up @@ -319,16 +321,16 @@ 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
uv pip install jupyter
cd plotly/labextension
npm ci
npm run build
cd ../doc
cd ../..
fi
cd ..

- run:
name: make html
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ doc/.ipynb_checkpoints
tags
doc/check-or-enforce-order.py
plotly/package_data/widgetbundle.js
plotly/labextension/static
plotly/labextension/lib

tests/percy/*.html
tests/percy/pandas2/*.html
6 changes: 3 additions & 3 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from distutils import log

project_root = os.path.dirname(os.path.abspath(__file__))
node_root = os.path.join(project_root, "js")
node_root = os.path.join(project_root, "plotly", "labextension")
is_repo = os.path.exists(os.path.join(project_root, ".git"))
node_modules = os.path.join(node_root, "node_modules")
targets = [
Expand All @@ -23,9 +23,9 @@
]
)

# Load plotly.js version from js/package.json
# Load plotly.js version from plotly/labextension/package.json
def plotly_js_version():
path = os.path.join(project_root, "js", "package.json")
path = os.path.join(project_root, "plotly", "labextension", "package.json")
with open(path, "rt") as f:
package_json = json.load(f)
version = package_json["dependencies"]["plotly.js"]
Expand Down
16 changes: 0 additions & 16 deletions js/package.json

This file was deleted.

12 changes: 12 additions & 0 deletions plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,15 @@ def hist_series(data_frame, **kwargs):
skip += ["figsize", "bins", "legend"]
new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip}
return histogram(data_frame, **new_kwargs)


def _jupyter_labextension_paths():
"""Called by Jupyter Lab Server to detect if it is a valid labextension and
to install the extension.
"""
return [
{
"src": "labextension/static",
"dest": "jupyterlab-plotly",
}
]
3 changes: 1 addition & 2 deletions plotly/io/_base_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def to_mimebundle(self, fig_dict):
class PlotlyRenderer(MimetypeRenderer):
"""
Renderer to display figures using the plotly mime type. This renderer is
compatible with JupyterLab (using the @jupyterlab/plotly-extension),
VSCode, and nteract.
compatible with VSCode and nteract.

mime type: 'application/vnd.plotly.v1+json'
"""
Expand Down
16 changes: 11 additions & 5 deletions plotly/io/_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def show(fig, renderer=None, validate=True, **kwargs):
)

default_renderer = env_renderer
elif ipython and ipython.get_ipython():
elif ipython:
# Try to detect environment so that we can enable a useful
# default renderer
if not default_renderer:
Expand Down Expand Up @@ -543,13 +543,19 @@ def show(fig, renderer=None, validate=True, **kwargs):
pass

# Check if we're running in ipython terminal
if not default_renderer and (
ipython.get_ipython().__class__.__name__ == "TerminalInteractiveShell"
):
ipython_info = ipython.get_ipython()
shell = ipython_info.__class__.__name__
if not default_renderer and (shell == "TerminalInteractiveShell"):
default_renderer = "browser"

# Check if we're running in a Jupyter notebook or JupyterLab
if not default_renderer and (shell == 'ZMQInteractiveShell') and (
type(ipython_info).__module__.startswith('ipykernel.')
):
default_renderer = 'plotly_mimetype'

# Fallback to renderer combination that will work automatically
# in the classic notebook (offline), jupyterlab, nteract, vscode, and
# in the jupyter notebook, jupyterlab, nteract, vscode, and
# nbconvert HTML export.
if not default_renderer:
default_renderer = "plotly_mimetype+notebook"
Expand Down
Loading