2

I try to write a custom extension for the Jupyter Notebook, as described here: https://towardsdatascience.com/how-to-write-a-jupyter-notebook-extension-a63f9578a38c

I use the Chrome developer tools on Windows7 to inspect and edit the Javascript source code of my custom extension. I hoped that when pressing F5 to update the page, my altered source code would be immediately applied.

However, as stated in the above mentioned article, I have to run

jupyter-contrib-nbextensions.exe install

and restart the server to refresh the notebook extension and to see the effects of my code changes.

Doing so after every little change is quite annoying when playing around and developing/debugging extensions.

=>Is there some sort of development option for automatically updating/reloading the extension?

4

1 回答 1

0

作为一种解决方法,我编写了一个扩展“工作区模块”:

https://github.com/stefanidelloth/treezjs/tree/master/jupyter_notebook_extension/workspace_module

该扩展的目的是导入文件“workspace.js”(如果它存在于笔记本文件夹中)。我的扩展的main.js是:

    define([
    'require',
    'jquery',
    'base/js/namespace',
    'base/js/events',
    'notebook/js/codecell' 
], function(
    requirejs,
    $,
    Jupyter,
    events,
    codecell   
) {
           
    var load_ipython_extension = function() {  
        if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
            init();                    
        } else {
            console.log("[workspace_module] Waiting for notebook availability")
            events.on("notebook_loaded.Notebook", function() {
                init();                           
            })
        }
    };
    
    function init(){
        
        console.log("[workspace_module] trying to load workspace.js")

        var moduleScript = document.createElement('script');
        moduleScript.setAttribute('type','module'); 
        
        moduleScript.setAttribute('src','workspace.js');    

        document.body.appendChild(moduleScript);
    }


    return {
        load_ipython_extension: load_ipython_extension       
    };

});

workspace.js重定向到我的实际扩展:

import './treezjs/src/treezJupyterNotebook.js';

这样,我可以在开发过程中调整我的代码,而无需重新执行安装命令。

于 2019-07-16T07:02:03.987 回答