Jupyter Notebook Custom.js Not Applied When Using "restarting & Run All"
In order to get the name of a running Jupyter notebook, I first added the following line in ~/.jupyter/custom/custom.js // Create a nb_name variable with the name of the notebook I
Solution 1:
custom.jskernel_ready.Kernel
event is triggered only once when the page is loaded, but it is not triggered after Restart & Run all
(or any variants of it). My solution to this problem is a bit hackie:
/**
* `kernel_ready` logic
*/functioncustom_kernel_ready_handler() {
IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"');
}
functionhandle_kernel_ready() {
// Create a nb_name variable with the name of the notebookconsole.log('kernel_ready.Kernel: handle_kernel_ready() was triggered!');
custom_kernel_ready_handler();
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
//this recursive behavior is esential for `restart` kernelhandle_kernel_ready();
});
}
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
handle_kernel_ready();
});
Hoping for better solutions ...
Post a Comment for "Jupyter Notebook Custom.js Not Applied When Using "restarting & Run All""