图表:http://链接有效,而file://链接无效

时间:2020-07-09 10:06:20

标签: html plotly

我正在尝试在绘图图表中使用超链接。如果使用http://,但不能使用file://(指向有效文件),则可以使链接正常工作。

下面的示例绘制了2个虚拟图:

  • 第一个绘制标题可点击的图表(http://)
  • 第二个图表制作了一个标题不可点击的图表(file://)

我无法弄清楚为什么第二张图表不起作用。我已经尝试将/和\(\)组合使用,但是现在运气很好。

有什么想法吗?

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()

0 个答案:

没有答案
相关问题