jupyter-notebook嵌入iframe

1,176 阅读1分钟

在jupyter配置目录新建custom.js文件

~/.jupyter/custom/custom.js

custom.js

define(['base/js/namespace'], function(Jupyter){
    Jupyter._target = '_self';
    //隐藏退出按钮和logo
    const quitWrap = document.querySelector("#shutdown_widget");
    const loginOutWrap = document.querySelector("#login_widget");
    const logoWrap = document.querySelector("#ipython_notebook");
    if (quitWrap) quitWrap.innerHTML = "";
    if (loginOutWrap) loginOutWrap.innerHTML = "";
    if (logoWrap) logoWrap.innerHTML = "";
});

在jupyter配置目录新建jupyter_config.py文件

~/.jupyter/jupyter_config.py
c.NotebookApp.allow_origin = '*' #Basic permission
c.NotebookApp.disable_check_xsrf = True #Otherwise Jupyter restricts you modifying the Iframed Notebook
c.NotebookApp.token = '' #In my case I didn't want to deal with securityc.NotebookApp.trust_xheaders = True #May or may not make a difference to you
c.NotebookApp.tornado_settings = { 'headers': { 'Content-Security-Policy': "frame-ancestors self *" } }
c.NotebookApp.allow_root = True
c.NotebookApp.ip='*'
c.NotebookApp.allow_remote_access = True
c.NotebookApp.port = 8888

启动

jupyter notebook