Skip to content Skip to sidebar Skip to footer

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.js kernel_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
 */
function custom_kernel_ready_handler() {
    IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"');
}

function handle_kernel_ready() {
    // Create a nb_name variable with the name of the notebook
     console.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` kernel
         handle_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""