问题描述
我正在使用Flask为单个用户托管UI.我一直试图做的事情是设置一种用户单击按钮的方式,该按钮使用标记语言在文档中预先指定的位置插入一些文本和图像.我最初是为此使用Jinja2的,但是问题是用户需要在插入数据后能够修改文档,以防他们需要对文本进行小的更改或添加行等.据我所知可以.不能用烧瓶渲染的模板完成.
I'm using Flask to host a UI for a single user. Something I've been trying to do is setup a way for user to click a button that inserts some text and images in a pre-specified place in a document using markup language. I originally used Jinja2 for this but the issue is the user needs to be able to modify the document after the data is inserted in case they need to make small changes to the text or add a line etc... which to my knowledge can't be done with a flask-rendered template.
我知道可以使用iframe将Jupyter笔记本(基于标记语言)引入UI,但是我做不到这一点.
I understand it is possible to bring a Jupyter Notebook (Which is based on markup language) into the UI using an iframe but I haven't had success in doing that.
我尝试过的事情:
- 将我的Jupyter笔记本配置为公开
- 使用我的公开Jupyter地址
<iframe width="400" height="400" src="http://10.33.75.112:8888/notebooks/Desktop/Tool/test.ipynb"/>
放置iframe放入我的HTML模板文件中...会弹出一个我无法与之交互的空白iframe - 沉迷于NBviewer和NBconvert,看看是否有某种方式可以将其集成,但没有成功.
- Configuring my Jupyter notebook to be public
- Placing an Iframe with my public Jupyter address
<iframe width="400" height="400" src="http://10.33.75.112:8888/notebooks/Desktop/Tool/test.ipynb"/>
into my HTML template file... which brings up a blank Iframe that I can't interact with - Messed around with NBviewer and NBconvert to see if there was some way I could integrate that but haven't had any success.
想法?
推荐答案
我找到了解决方案.
在Jupyter-notebook-config.py文件夹中,您需要取消注释和修改几个选项才能进行此操作.
In the Jupyter-notebook-config.py folder there are a couple options you need to uncomment and modify to get this going.
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.
Also Google Chrome has an error displaying iframes like this so use either Mozilla or IE.
这篇关于在烧瓶中渲染Jupyter Notebook Iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!