【问题标题】:Render a Jupyter Notebook Iframe in Flask在 Flask 中渲染 Jupyter Notebook iframe
【发布时间】:2017-10-15 23:11:49
【问题描述】:

我正在使用 Flask 为单个用户托管 UI。我一直在尝试做的事情是设置一种方式让用户单击一个按钮,该按钮使用标记语言在文档中的预先指定的位置插入一些文本和图像。我最初为此使用了 Jinja2,但问题是用户需要能够在插入数据后修改文档,以防他们需要对文本进行小的更改或添加一行等......据我所知可以不能使用烧瓶渲染的模板来完成。

我知道可以使用 iframe 将 Jupyter Notebook(基于标记语言)引入 UI,但我没有成功。

我的尝试:

  1. 将我的 Jupyter 笔记本配置为公开
  2. 使用我的公共 Jupyter 地址 <iframe width="400" height="400" src="http://10.33.75.112:8888/notebooks/Desktop/Tool/test.ipynb"/> 放置一个 iframe 进入我的 HTML 模板文件...这会显示一个我无法与之交互的空白 iframe
  3. 搞砸了 NBviewer 和 NBconvert,看看是否有什么方法可以集成,但没有任何成功。

想法?

【问题讨论】:

    标签: python-2.7 flask jinja2 jupyter-notebook flask-wtforms


    【解决方案1】:

    我找到了解决方案。

    在 Jupyter-notebook-config.py 文件夹中,您需要取消注释和修改几个选项才能执行此操作。

    c.NotebookApp.allow_origin = '*' #Basic permission
    c.NotebookApp.disable_check_xsrf = True #Otherwise Jupyter restricts you modifying the Iframed Notebook
    c.NotebookApp.ip = 'ENTER_YOUR_JUPYTER_IP_ADDRESS' #Appears in the top browser bar when you launch jupyter
    c.NotebookApp.port = 8888 #Your choice of port
    c.NotebookApp.token = '' #In my case I didn't want to deal with security
    c.NotebookApp.trust_xheaders = True #May or may not make a difference to you
    
    c.NotebookApp.tornado_settings = {
    'headers': {
    'Content-Security-Policy': "frame-ancestors 'http://127.0.0.1:5000/' 'self' "
    }
    } #assuming your Flask localhost is 127.0.0.1:5000
    

    然后在 HTML 中:

    <iframe width="1000" height="1000"  src="http://ENTER_YOUR_JUPYTER_IP_ADDRESS:8888/notebooks/Desktop/test.ipynb"/>
    

    编辑:Google Chrome 也有错误显示这样的 iframe,所以请使用 Mozilla 或 IE。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-22
      • 2020-02-28
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      相关资源
      最近更新 更多