在Flask中可以使用iPython小部件吗?

2024-03-29 03:30:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在Jupyter笔记本电脑中使用iPython widgets,但我所依赖的启用App模式的扩展不起作用,所以我决定尝试将其全部重写为Python/Flask,但我不知道如何,或者是否有可能,在Flask视图中使用iPython小部件(尤其是交互式)?在

import ipywidgets as widgets

items_layout = widgets.Layout(flex='1 1 auto',
                      width='400px', height='200px')

box_layout = widgets.Layout(display='flex',
                    flex_flow='row',
                    align_items='stretch',
                    width='100%')

instruction = widgets.Textarea(description="Command",
                               value = "",
                               layout = items_layout)

code = widgets.Textarea(description="Code",  
                        value = "",
                        layout = items_layout)

interactive_plot = widgets.interactive(run_code, trigger = instruction)

items = [interactive_plot, code]
box = widgets.Box(children=items, layout=box_layout)
display(box)

Tags: boxflaskipythondisplaycodeitemsdescriptionwidgets
1条回答
网友
1楼 · 发布于 2024-03-29 03:30:02

下面是来自ipywidgets存储库issue关于类似主题的响应。在

In order for the widgets to do something, they must be hooked up to a kernel to do the computation. This requires some extra javascript code and a server somewhere that is providing the python kernel. The web3 example shows one way to do this.

在web服务中使用ipywidgets的Example。在

但是,您将无法用Python编写小部件代码。小部件的整个显示都是用JavaScript代码完成的。在

相关问题 更多 >