使用jupyter笔记本,切换按钮的输出工作顺利。但是,当我将其另存为 html 时。HTML 无法显示切换按钮的输出下图是html格式,切换按钮无法显示输出。但在 jupyter 中它工作得很好。https://i.stack.imgur.com/WMpST.png 我正在使用这个代码。import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport ipywidgets as widgetsfrom IPython.display import display, Markdown, clear_output, HTMLfrom IPython.display import displayfrom ipywidgets.embed import embed_minimal_htmldata=[[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 --to html --no-input try.ipynb!jupyter nbconvert --to html --no-input --template basic --output try.html try.ipynb我仍在探索使用这些小部件,但我被困在这里。
目前暂无任何回答
- 0 回答
- 0 关注
- 92 浏览
添加回答
举报
0/150
提交
取消