我正在尝试在绘图图表中使用超链接。如果使用http://,但不能使用file://(指向有效文件),则可以使链接正常工作。
下面的示例绘制了2个虚拟图:
我无法弄清楚为什么第二张图表不起作用。我已经尝试将/和\(\)组合使用,但是现在运气很好。
有什么想法吗?
import plotly.graph_objs as go
import plotly.offline as pl
langs = ['C', 'C++',]
students = [23,17]
fig = go.Figure(data=[go.Bar(x = langs, y = students)])
title1 = '<a href="http://bbc.co.uk">Test1</a>'
title2 = '<a href="file://server/referenced.html">Test2</a>'
fig.update_layout(title=title1)
c1 = pl.plot(fig, include_plotlyjs=False, output_type='div')
fig.update_layout(title=title2)
c2 = pl.plot(fig, include_plotlyjs=False, output_type='div')
res = """
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
</head>
<body>
<p>{0}</p>
<p>{1}</p?
</body>
</html>
""".format(c1, c2)
text_file = open("sample.html", "w")
n = text_file.write(res)
text_file.close()