我正在使用 Flask 为单个用户托管 UI。我一直在尝试做的事情是设置一种方法,让用户单击一个按钮,使用标记语言在文档中预先指定的位置插入一些文本和图像。我最初使用 Jinja2 来实现此目的,但问题是用户需要能够在插入数据后修改文档,以防他们需要对文本进行小的更改或添加一行等......据我所知可以'不需要使用烧瓶渲染的模板来完成。
我知道可以使用 iframe 将 Jupyter Notebook(基于标记语言)引入 UI,但我还没有成功做到这一点。
我尝试过的:
- 将我的 Jupyter 笔记本配置为公开
- 使用我的公共 Jupyter 地址放置一个 Iframe
<iframe width="400" height="400" src="http://10.33.75.112:8888/notebooks/Desktop/Tool/test.ipynb"/>
进入我的 HTML 模板文件...这会显示一个我无法与之交互的空白 Iframe
- 搞乱了 NBviewer 和 NBconvert,看看是否有某种方法可以整合它,但没有取得任何成功。
Ideas?
我找到了解决方案。
在 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。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)