繁体   English   中英

带有“href”的 plotly 树图元素不适用于本地相对 html 路径

[英]plotly treemap element with “href” not working with local relative html paths

我在文本中有带有 href 的简单表格。 href 指向本地 html 文件的相对路径。 但是点击它不会打开页面。 有没有办法做到这一点/好的解决方法?

文件夹结构如下。 由于根会改变,所以需要相对路径。

--root
--root/index.html
--root/files/file1.html
--root/files/file2.html



import plotly.express as px
df = px.data.gapminder().query("year == 2007")

link_ref = '<a href="files/file1.html">{}</a>'
df['country'] = df['country'].apply(lambda item: link_ref.format(item))
fig = px.treemap(df, path=[ 'continent', 'country'], values='pop',
                  color='lifeExp', hover_data=['iso_alpha'])
fig.write_html("index.html")

注意:以http开头的链接有效。 Plotly:带有“href”的树形图元素不起作用

link_ref = '<a href="http://google.com">{}</a>'

在此处输入图像描述

更新:

以下链接部分有效。

link_ref = '<a href="http:///files/file1.html">{}</a>'

出于安全原因,文件链接是一个问题。 我用 IE 11 测试了这段代码,它运行良好,没有问题。 对于 Firefox、Chrome 和 Edge,它不起作用。

您可以在浏览器中禁用此安全检查或使用扩展程序。 http://kb.mozillazine.org/Links_to_local_pages_do_not_work

import plotly.express as px
df = px.data.gapminder().query("year == 2007")

link_ref = '<a href="./text.html">{}</a>'
df['country'] = df['country'].apply(lambda item: link_ref.format(item))
fig = px.treemap(df, path=[ 'continent', 'country'], values='pop',
                  color='lifeExp', hover_data=['iso_alpha'])
fig.write_html("index.html")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM