Python ReferenceError:添加到HTML模板时未定义绘图
我正在尝试将plotly表添加到HTML文件中。但当我运行此代码时,会出现以下错误: 添加输出时出现Javascript错误! 引用错误:未定义“Plotly” 有关更多详细信息,请参阅浏览器javascript控制台 我已经搜索并找到了其他有同样问题的人,但还没有找到解决方案。我在Jupyter笔记本上运行这个代码。有人知道可能出了什么问题吗Python ReferenceError:添加到HTML模板时未定义绘图,python,plotly,Python,Plotly,我正在尝试将plotly表添加到HTML文件中。但当我运行此代码时,会出现以下错误: 添加输出时出现Javascript错误! 引用错误:未定义“Plotly” 有关更多详细信息,请参阅浏览器javascript控制台 我已经搜索并找到了其他有同样问题的人,但还没有找到解决方案。我在Jupyter笔记本上运行这个代码。有人知道可能出了什么问题吗 import numpy as np import pandas as pd from jinja2 import Environment, FileS
import numpy as np
import pandas as pd
from jinja2 import Environment, FileSystemLoader
import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, iplot
import plotly.io as pio
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv')
# index = df.index
rowEvenColor = 'white'
rowOddColor = 'lavender'
fig_num = 1
for _,df_chunk in df.groupby(np.arange(len(df))//10):
fig = go.Figure(data=[go.Table(
columnorder = [1,2, 3, 4],
columnwidth = [30,400, 40, 60],
header=dict(values=list(df_chunk.columns),
fill_color='navy',
font_color='white',
align=['center', 'left', 'center', 'center']),
cells=dict(values=[df_chunk.Rank, df_chunk.State, df_chunk.Postal, df_chunk.Population],
fill_color = [[rowOddColor,rowEvenColor]*len(df_chunk.index)],
font_size=12,
height=60,
align=['center', 'left', 'center', 'left']))
])
fig.update_layout(width=1000, height=600)
# fig.show()
if not os.path.exists("images"):
os.mkdir("images")
# print("saving fig" + str(fig_num))
pio.write_image(fig, 'images/fig' + str(fig_num) + '.png', engine="orca")
fig_num += 1
然后我创建了一个HTML模板
<html>
<head lang-"en">
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<mega charset = "UTF-8">
<title> {{title}}</title>
</head>
<body>
<h2> Test header </h2>
{{ plotly_table }}
</body>
</html>
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("test.html")
template_vars = {"title" : "test title",
"plotly_table" : fig.to_html()}
html_out = template.render(template_vars)
display(HTML(html_out))