python - 在 GitHub Pages 上显示交互式绘图图表(.html 文件)

标签 python html markdown plotly github-pages

我已经创建了以下 plotly plotly 是这样的:

import plotly
labels = ['Oxygen', 'Hydrogen', 'Carbon_Dioxide', 'Nitrogen']
values = [4500, 2500, 1053, 500]

trace = plotly.graph_objs.Pie(labels=labels, values=values)
plotly.offline.plot([trace], filename='basic-pie-chart')

然后我创建了这样的html:
print(plotly.offline.plot([trace], include_plotlyjs=False, output_type='div'))

运行上面的代码会生成一个 .html 文件,我可以在浏览器中查看该文件。

有没有办法在我的 GitHub 页面上的 Markdown 文件中间显示 .html 文件,以便我可以使用 plotly 的交互功能?

Here is a similar question that I asked

最佳答案

如果您使用 Jekyll在您的 GitHub 页面站点中。

准备数据:

import plotly.graph_objects as go

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500, 2500, 1053, 500]
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.show()

生成 HTML 文件:
import plotly.io as pio

pio.write_html(fig, file='figure.html', auto_open=True)

上传 figure.html文件并将其提交到 _includes站点存储库根目录中的文件夹。

现在,如果您正在使用 markdown要创建您的帖子,您可以使用 include标记和调用 figure.html在你的帖子里有这样的东西:
{% include figure.html %}

将此行提交到您的帖子 .md _posts 中的文件文件夹。检查结果。

关于python - 在 GitHub Pages 上显示交互式绘图图表(.html 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60513164/

相关文章:

python - 使用 HAproxy 时出现 Flask-SQLAlchemy "MySQL server has gone away"

python - Django : How can I implement a remember me key on my login page

python - 从 Pandas Dataframe 的列中删除 URL

HTML5视频本地源+网页源

linux - 使用 SED 命令删除 Markdown 文件中的代码块

mediawiki - 有没有任何工具可以将 Markdown 转换为其他格式的 Wiki 文本

python - 正确的排名损失实现

javascript - CSS 规则未应用于动态生成的元素

javascript - 检查多个 div 是否同时可见

html - 没有 .html 扩展名的链接,无需创建目录