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

Commit 5cb371e

Browse files
committed
Make sure kernel is ready before registering comm in classic notebook
1 parent ffc6e4d commit 5cb371e

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

jupyter_dash/nbextension/main.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ define([
66
], function(Jupyter, utils){
77

88
function load_ipython_extension(){
9-
console.info('this is my first extension');
10-
119
var notebookUrl = window.location.href
1210
var baseUrl = utils.get_body_data('baseUrl');
1311
var baseNotebooks = baseUrl + "notebooks"
1412
var n = notebookUrl.search(baseNotebooks)
1513
var jupyterServerUrl = notebookUrl.slice(0, n)
16-
console.log(jupyterServerUrl)
17-
console.log(baseUrl)
1814

19-
Jupyter.notebook.kernel.comm_manager.register_target('jupyter_dash',
20-
function(comm, msg) {
21-
// Register handlers for later messages:
22-
comm.on_msg(function(msg) {
23-
var msgData = msg.content.data;
24-
console.log(msgData)
25-
if (msgData.type === 'base_url_request') {
26-
comm.send({
27-
type: 'base_url_response',
28-
server_url: jupyterServerUrl,
29-
base_subpath: baseUrl,
30-
frontend: "notebook"
15+
var register_comm = function() {
16+
Jupyter.notebook.kernel.comm_manager.register_target('jupyter_dash',
17+
function (comm, msg) {
18+
// Register handlers for later messages:
19+
comm.on_msg(function (msg) {
20+
var msgData = msg.content.data;
21+
console.log(msgData)
22+
if (msgData.type === 'base_url_request') {
23+
comm.send({
24+
type: 'base_url_response',
25+
server_url: jupyterServerUrl,
26+
base_subpath: baseUrl,
27+
frontend: "notebook"
28+
});
29+
}
3130
});
32-
}
33-
});
34-
});
31+
});
32+
};
33+
34+
Jupyter.notebook.events.on('kernel_ready.Kernel', register_comm)
3535
}
3636

3737
return {

0 commit comments

Comments
 (0)