Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用ipywidgets在HMTL中显示toogle按钮的输出?_Python_Html_Jupyter Notebook_Ipywidgets - Fatal编程技术网

Python 如何使用ipywidgets在HMTL中显示toogle按钮的输出?

Python 如何使用ipywidgets在HMTL中显示toogle按钮的输出?,python,html,jupyter-notebook,ipywidgets,Python,Html,Jupyter Notebook,Ipywidgets,使用jupyter笔记本,切换按钮的输出工作正常。但是,当我将其另存为html时。HTML无法显示切换按钮的输出 下图是html格式,切换按钮无法显示输出。但在jupyter,它的工作很好 我正在使用这个代码 import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import ipywidgets as widgets from IPython.display i

使用jupyter笔记本,切换按钮的输出工作正常。但是,当我将其另存为html时。HTML无法显示切换按钮的输出

下图是html格式,切换按钮无法显示输出。但在jupyter,它的工作很好

我正在使用这个代码

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import ipywidgets as widgets
from IPython.display import display, Markdown, clear_output, HTML
from IPython.display import display
from ipywidgets.embed import embed_minimal_html

data=[[47,15,3,5,7],[33,13,4,7,2],[25,17,9,3,5]]
df = pd.DataFrame(data, columns=['VAR_A','VAR_B','VAR_C','VAR_D','VAR_E'])

toggle = widgets.ToggleButtons(options = df.columns, description = 'Variables:', button_style = '')
out = widgets.Output()

def toggle_plot(button):
    with out:
        if button['new']:
            out.clear_output()
            plt.ioff()
            ax=plt.gca()
            sns.barplot(x=toggle.value, data=df)
            display(ax.figure)
            plt.clf() 
        else:
            out.clear_output()

toggle.observe(toggle_plot, 'value')
display(toggle)
display(out)

embed_minimal_html('try.html', views=[toggle], title='try')
我还尝试在jupyter笔记本中使用这两个函数进行保存,但其保存为空html。
!jupyter nbconvert--转换为html--无需输入try.ipynb

!jupyter nbconvert--到html--无输入--模板基本--输出try.html try.ipynb

我仍在探索如何使用这些小部件,但我仍停留在这里

正如jasongrout所解释的,不可能实现您想要做的事情,因为小部件需要一个内核来执行

但是你可以看看你想要什么