我想构建一个使用github页面的站点,我遇到了一些问题,因为我正在尝试将下面的交互情节嵌入到我的标记文件(利用plotly.express.choropleth获取地图)中。我已经尝试了多个选项,例如将图形保存到html文件中,然后尝试使用以下选项将html文件添加到标记文件中:
- {% include_relative figure.html %}
- {% include figure.html %}
- <embed type="text/html" src="figure.html" width="600" height="400"></embed>
- <iframe>
- <object>
- <div>
这些行最后都没有我的数字出现在减价文件中。我可能用错了,因为我不是最熟悉的,但我希望有人能找到我做错了什么,或如何解决这个问题。
如果它有任何用处,下面是我试图显示的图形的代码,以及我如何保存它:
fig = px.choropleth(feat_df, geojson=counties, locations='id', color='hurr_tot',
color_continuous_scale="viridis",
range_color=(0, 40), center = {"lat": 38, "lon": -100},
scope="usa",
hover_name="county", hover_data=['code','hurr_tot'],
labels={'hurr_tot':'Hurricanes'}
)
fig.update_traces(hovertemplate="County : %{hovertext} <br>State : %{customdata[0]}, <br>Hurricanes : %{customdata[1]}")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}, width=650, height=400, newshape_line_color='#000000')
fig.show()
pio.write_html(fig, file='figure.html')
以下是我的html文件:
<html>
<head><meta charset="utf-8" /></head>
<body>
<div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
<script type="text/javascript">/**
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:" ...
</body>
</html>
发布于 2022-03-01 16:45:34
我很遗憾地告诉你,在“raw”README.md GitHub中插入交互式情节是不可能的。幸运的是,还有另一个GitHub替代方案:GitHub Pages。在这里,我附加了一个相当的好教程,介绍如何轻松地准备存储库,以获得一个网页来加载您的交互式绘图,并浏览您保存在存储库中的所有交互图。
希望它能帮到你!密谋快乐!
https://stackoverflow.com/questions/70302784
复制相似问题