在jupyter noteb中嵌入绘图html时出现Javascript错误

2024-10-02 10:32:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试着把HTML从plotly嵌入到Jupyter笔记本中。这是HTML

<html>
<head>
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
  <div id="7979e646-13e6-4f44-8d32-d8effc3816df" style="height: 525; width: 100%;" class="plotly-graph-div"></div><script type="text/javascript">window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL="https://plot.ly";Plotly.newPlot("7979e646-13e6-4f44-8d32-d8effc3816df", [{"x": [1, 2, 3], "y": [3, 1, 6]}], {}, {"showLink": false, "linkText": ""})</script>
</body>
</html>

如果我把它放在一个普通的HTML文件中,然后在浏览器中打开它,它就可以正常工作了。另一方面,如果我把它放在Jupyter的%%html单元格中,或者如果我使用IPython.display模块中的display(HTML(html_string)),我会得到以下错误:

^{pr2}$

是什么引起的?在


Tags: httpsdivplothtmldisplaylyscriptjupyter

热门问题