Skip to content

Commit 6944e92

Browse files
committed
Merge JupyterDash with Dash
1 parent e145b40 commit 6944e92

26 files changed

+2389
-42
lines changed

Diff for: .pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ max-attributes=20
412412
max-bool-expr=5
413413

414414
# Maximum number of branch for function / method body
415-
max-branches=12
415+
max-branches=15
416416

417417
# Maximum number of locals for function / method body
418418
max-locals=15

Diff for: .pylintrc39

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ max-attributes=20
513513
max-bool-expr=5
514514

515515
# Maximum number of branch for function / method body.
516-
max-branches=12
516+
max-branches=15
517517

518518
# Maximum number of locals for function / method body.
519519
max-locals=15

Diff for: @plotly/dash-generator-test-component-typescript/package-lock.json

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: @plotly/dash-generator-test-component-typescript/src/components/MemoTypeScriptComponent.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const MemoTypeScriptComponent = (props: TypescriptComponentProps) => (
1414
<div id={props.id}>{props.required_string}</div>
1515
);
1616

17-
export default React.memo(MemoTypeScriptComponent);
17+
export default React.memo(MemoTypeScriptComponent, () => true);

Diff for: @plotly/dash-generator-test-component-typescript/src/components/StandardComponent.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ StandardComponent.propTypes = {
1717
children: PropTypes.node,
1818
}
1919

20-
export default StandardComponent
20+
export default React.memo(StandardComponent, (prevProps,nextProps) => true)

Diff for: @plotly/dash-jupyterlab/.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

Diff for: @plotly/dash-jupyterlab/lib/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
2+
import '../style/index.css';
3+
/**
4+
* Initialization data for the jupyterlab-dash extension.
5+
*/
6+
declare const extension: JupyterFrontEndPlugin<void>;
7+
export default extension;

Diff for: @plotly/dash-jupyterlab/lib/index.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const application_1 = require("@jupyterlab/application");
4+
const coreutils_1 = require("@jupyterlab/coreutils");
5+
const notebook_1 = require("@jupyterlab/notebook");
6+
const console_1 = require("@jupyterlab/console");
7+
const widgets_1 = require("@lumino/widgets");
8+
require("../style/index.css");
9+
class DashIFrameWidget extends widgets_1.Widget {
10+
/**
11+
* Construct a new DashIFrameWidget.
12+
*/
13+
constructor(port, url) {
14+
super();
15+
this.id = port;
16+
this.title.label = `Dash (port: ${port})`;
17+
this.title.closable = true;
18+
this.addClass('jp-dashWidget');
19+
// Add jp-IFrame class to keep drag events from being lost to the iframe
20+
// See https://github.com/phosphorjs/phosphor/issues/305
21+
// See https://github.com/jupyterlab/jupyterlab/blob/master/packages/apputils/style/iframe.css#L17-L35
22+
this.addClass('jp-IFrame');
23+
const serviceUrl = url;
24+
const iframeElement = document.createElement('iframe');
25+
iframeElement.setAttribute('baseURI', serviceUrl);
26+
this.iframe = iframeElement;
27+
this.iframe.src = serviceUrl;
28+
this.iframe.id = 'iframe-' + this.id;
29+
this.node.appendChild(this.iframe);
30+
}
31+
/**
32+
* Handle update requests for the widget.
33+
*/
34+
onUpdateRequest(msg) {
35+
this.iframe.src += '';
36+
}
37+
}
38+
function activate(app, restorer, notebooks, consoles) {
39+
// Declare a widget variable
40+
let widgets = new Map();
41+
// Watch notebook creation
42+
notebooks.widgetAdded.connect((sender, nbPanel) => {
43+
// const session = nbPanel.session;
44+
const sessionContext = nbPanel.sessionContext;
45+
sessionContext.ready.then(() => {
46+
const session = sessionContext.session;
47+
let kernel = session.kernel;
48+
registerCommTarget(kernel, widgets, app);
49+
});
50+
});
51+
// Watch console creation
52+
consoles.widgetAdded.connect((sender, consolePanel) => {
53+
const sessionContext = consolePanel.sessionContext;
54+
sessionContext.ready.then(() => {
55+
const session = sessionContext.session;
56+
let kernel = session.kernel;
57+
registerCommTarget(kernel, widgets, app);
58+
});
59+
});
60+
}
61+
function registerCommTarget(kernel, widgets, app) {
62+
kernel.registerCommTarget('dash', (comm, msg) => {
63+
comm.onMsg = (msg) => {
64+
let msgData = msg.content.data;
65+
if (msgData.type === 'show') {
66+
let widget;
67+
if (!widgets.has(msgData.port)) {
68+
// Create a new widget
69+
widget = new DashIFrameWidget(msgData.port, msgData.url);
70+
widget.update();
71+
widgets.set(msgData.port, widget);
72+
// Add instance tracker stuff
73+
}
74+
else {
75+
widget = widgets.get(msgData.port);
76+
}
77+
if (!widget.isAttached) {
78+
// Attach the widget to the main work area
79+
// if it's not there
80+
app.shell.add(widget, 'main');
81+
widget.update();
82+
}
83+
else {
84+
// Refresh the widget
85+
widget.update();
86+
}
87+
// Activate the widget
88+
app.shell.activateById(widget.id);
89+
}
90+
else if (msgData.type === 'base_url_request') {
91+
// Build server url and base subpath.
92+
const baseUrl = coreutils_1.PageConfig.getBaseUrl();
93+
const baseSubpath = coreutils_1.PageConfig.getOption('baseUrl');
94+
const n = baseUrl.lastIndexOf(baseSubpath);
95+
const serverUrl = baseUrl.slice(0, n);
96+
comm.send({
97+
type: 'base_url_response',
98+
server_url: serverUrl,
99+
base_subpath: baseSubpath,
100+
frontend: "jupyterlab",
101+
});
102+
}
103+
};
104+
});
105+
}
106+
/**
107+
* Initialization data for the jupyterlab-dash extension.
108+
*/
109+
const extension = {
110+
id: 'jupyterlab_dash',
111+
autoStart: true,
112+
requires: [application_1.ILayoutRestorer, notebook_1.INotebookTracker, console_1.IConsoleTracker],
113+
activate: activate
114+
};
115+
exports.default = extension;

Diff for: @plotly/dash-jupyterlab/package.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "@plotly/dash-jupyterlab",
3+
"version": "0.4.3",
4+
"description": "A JupyterLab extensions for rendering Plotly Dash apps",
5+
"keywords": [
6+
"jupyter",
7+
"jupyterlab",
8+
"jupyterlab-extension"
9+
],
10+
"homepage": "https://github.com/plotly/dash",
11+
"bugs": {
12+
"url": "https://github.com/plotly/dash/issues"
13+
},
14+
"license": "MIT",
15+
"author": "Plotly",
16+
"files": [
17+
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
18+
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
19+
],
20+
"main": "lib/index.js",
21+
"types": "lib/index.d.ts",
22+
"repository": {
23+
"type": "git",
24+
"url": "git+https://github.com/plotly/dash.git"
25+
},
26+
"scripts": {
27+
"build": "tsc",
28+
"build:pack": "jlpm run prepare && jlpm pack --filename ../../dash/labextension/dist/dash-jupyterlab.tgz && jlpm run build:copy",
29+
"build:copy": "cp package.json ../../dash/labextension/dist/dash-jupyterlab.tgz",
30+
"clean": "rimraf lib",
31+
"prepare": "jlpm run clean && jlpm run build",
32+
"prettier": "prettier --write '{!(package),src/**,!(lib)/**}{.js,.jsx,.ts,.tsx,.css,.json,.md}'",
33+
"watch": "tsc -w"
34+
},
35+
"dependencies": {
36+
"@jupyterlab/application": "^2.0.0 || ^3.0.0",
37+
"@jupyterlab/notebook": "^2.0.0 || ^3.0.0",
38+
"@jupyterlab/console": "^2.0.0 || ^3.0.0"
39+
},
40+
"devDependencies": {
41+
"prettier": "2.0.5",
42+
"rimraf": "3.0.2",
43+
"typescript": "3.9.3"
44+
},
45+
"jupyterlab": {
46+
"extension": true
47+
}
48+
}

0 commit comments

Comments
 (0)