Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 5859255

Browse files
committed
Make jupyter_server_proxy optional, auto-install jupyter extension
1 parent f162c0d commit 5859255

File tree

8 files changed

+37
-25
lines changed

8 files changed

+37
-25
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
recursive-include jupyter_dash/nbextension *.json
22
recursive-include jupyter_dash/nbextension *.js
3+
recursive-include extensions/jupyterlab/*.tgz

extensions/jupyterlab/lib/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DashIFrameWidget extends widgets_1.Widget {
1010
/**
1111
* Construct a new DashIFrameWidget.
1212
*/
13-
constructor(port) {
13+
constructor(port, url) {
1414
super();
1515
this.id = port;
1616
this.title.label = `Dash (port: ${port})`;
@@ -20,8 +20,7 @@ class DashIFrameWidget extends widgets_1.Widget {
2020
// See https://github.com/phosphorjs/phosphor/issues/305
2121
// See https://github.com/jupyterlab/jupyterlab/blob/master/packages/apputils/style/iframe.css#L17-L35
2222
this.addClass('jp-IFrame');
23-
const baseUrl = coreutils_1.PageConfig.getBaseUrl();
24-
const serviceUrl = `${baseUrl}proxy/${port}`;
23+
const serviceUrl = url;
2524
const iframeElement = document.createElement('iframe');
2625
iframeElement.setAttribute('baseURI', serviceUrl);
2726
this.iframe = iframeElement;
@@ -67,7 +66,7 @@ function registerCommTarget(kernel, widgets, app) {
6766
let widget;
6867
if (!widgets.has(msgData.port)) {
6968
// Create a new widget
70-
widget = new DashIFrameWidget(msgData.port);
69+
widget = new DashIFrameWidget(msgData.port, msgData.url);
7170
widget.update();
7271
widgets.set(msgData.port, widget);
7372
// Add instance tracker stuff

extensions/jupyterlab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab-dash",
3-
"version": "0.2.0-alpha.1",
3+
"version": "0.2.0-alpha.2",
44
"description": "A JupyterLab extensions for rendering Plotly Dash apps",
55
"keywords": [
66
"jupyter",

extensions/jupyterlab/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DashIFrameWidget extends Widget {
2222
/**
2323
* Construct a new DashIFrameWidget.
2424
*/
25-
constructor(port: string) {
25+
constructor(port: string, url: string) {
2626
super();
2727

2828
this.id = port;
@@ -35,8 +35,7 @@ class DashIFrameWidget extends Widget {
3535
// See https://github.com/jupyterlab/jupyterlab/blob/master/packages/apputils/style/iframe.css#L17-L35
3636
this.addClass('jp-IFrame');
3737

38-
const baseUrl = PageConfig.getBaseUrl();
39-
const serviceUrl = `${baseUrl}proxy/${port}`;
38+
const serviceUrl = url;
4039
const iframeElement = document.createElement('iframe');
4140
iframeElement.setAttribute('baseURI', serviceUrl);
4241
this.iframe = iframeElement;
@@ -62,6 +61,7 @@ class DashIFrameWidget extends Widget {
6261
interface DashMessageData {
6362
type: string;
6463
port: string;
64+
url: string;
6565
}
6666

6767
function activate(
@@ -110,7 +110,7 @@ function registerCommTarget(
110110
let widget: DashIFrameWidget;
111111
if (!widgets.has(msgData.port)) {
112112
// Create a new widget
113-
widget = new DashIFrameWidget(msgData.port);
113+
widget = new DashIFrameWidget(msgData.port, msgData.url);
114114
widget.update();
115115
widgets.set(msgData.port, widget);
116116

jupyter_dash/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ def _jupyter_nbextension_paths():
1111
"require": "jupyter_dash/main",
1212
}
1313
]
14+
15+
16+
__labextension_version__ = "v0.2.0-alpha.2"

jupyter_dash/comms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _jupyter_comm_response_received():
3030
return bool(_jupyter_config)
3131

3232

33-
def _request_jupyter_proxy_config(timeout=2):
33+
def _request_jupyter_config(timeout=2):
3434
# Heavily inspired by implementation of CaptureExecution in the
3535
if _dash_comm.kernel is None:
3636
# Not in jupyter server setting
@@ -61,7 +61,7 @@ def capture_event(stream, ident, parent):
6161
# give up
6262
raise EnvironmentError(
6363
"Unable to communicate with the jupyter_dash notebook or JupyterLab \n"
64-
"extension required to infer proxy configuration."
64+
"extension required to infer Jupyter configuration."
6565
)
6666
if _jupyter_comm_response_received():
6767
break

jupyter_dash/jupyter_app.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,13 @@
88

99

1010
from IPython.display import IFrame, display
11-
from .comms import _dash_comm, _jupyter_config, _request_jupyter_proxy_config
11+
from .comms import _dash_comm, _jupyter_config, _request_jupyter_config
1212

1313

1414
class JupyterDash(dash.Dash):
1515
@classmethod
16-
def infer_jupyter_proxy_config(cls):
17-
try:
18-
import jupyter_server_proxy
19-
except Exception:
20-
raise ImportError(
21-
"The infer_jupyter_proxy_config function requires the "
22-
"jupyter_server_proxy Python package"
23-
)
24-
_request_jupyter_proxy_config()
16+
def infer_jupyter_config(cls):
17+
_request_jupyter_config()
2518

2619
def __init__(self, server_url=None, **kwargs):
2720

@@ -30,12 +23,19 @@ def __init__(self, server_url=None, **kwargs):
3023
self.default_requests_pathname_prefix = None
3124
self.default_mode = 'external'
3225

33-
if 'base_subpath' in _jupyter_config:
26+
# See if jupyter_server_proxy is installed
27+
try:
28+
import jupyter_server_proxy
29+
self._server_proxy = True
30+
except Exception:
31+
self._server_proxy = False
32+
33+
if 'base_subpath' in _jupyter_config and self._server_proxy:
3434
self.default_requests_pathname_prefix = (
3535
_jupyter_config['base_subpath'].rstrip('/') + '/proxy/{port}/'
3636
)
3737

38-
if 'server_url' in _jupyter_config:
38+
if 'server_url' in _jupyter_config and self._server_proxy:
3939
self.default_server_url = _jupyter_config['server_url']
4040

4141
if 'frontend' in _jupyter_config:
@@ -206,7 +206,8 @@ def wait_for_app():
206206
# Update front-end extension
207207
_dash_comm.send({
208208
'type': 'show',
209-
'port': port
209+
'port': port,
210+
'url': dashboard_url,
210211
})
211212

212213
@classmethod

setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from setuptools import setup
22

3+
from jupyter_dash import __labextension_version__
4+
35
setup(
46
name='jupyter-dash',
57
version='0.0.1a1',
@@ -13,9 +15,15 @@
1315
("share/jupyter/nbextensions/jupyter_dash", [
1416
"jupyter_dash/nbextension/main.js",
1517
]),
16-
# like `jupyter nbextension enable --sys-prefix`
18+
# like `jupyter nbextension enable --sys-prefix`
1719
("etc/jupyter/nbconfig/notebook.d", [
1820
"jupyter_dash/nbextension/jupyter_dash.json"
1921
]),
22+
# Place jupyterlab extension in extension directory
23+
("share/jupyter/lab/extensions", [
24+
"extensions/jupyterlab/jupyterlab-dash-{ver}.tgz".format(
25+
ver=__labextension_version__
26+
)
27+
]),
2028
]
2129
)

0 commit comments

Comments
 (0)