python - 具有 “href” 的绘图 TreeMap 元素不适用于本地相对 html 路径

标签 python plotly plotly-dash plotly-python

我在文本中有一个带有 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: treemap element with "href" not working
link_ref = '<a href="http://google.com">{}</a>'
enter image description here
更新:
以下链接部分有效。
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")

关于python - 具有 “href” 的绘图 TreeMap 元素不适用于本地相对 html 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62967338/

相关文章:

python - Pandas:查找 CSV 中接下来每 10 个数据点的平均值

Python Kanren 关系

r - 如何使用 R Shiny 中的plotly proxy 将文本注释添加到绘图中

python - 将凭据传递给 Dash 的基本身份验证,因此用户无需再次输入

python - 如何在同一标记上连续注册两个点击事件

python-3.x - 具有多个下拉输入不工作的 Plotly 破折号图

python - 使用正则表达式查找大写字母不在句子开头的单词

python - Pandas groupby : How to get a union of strings

r - R plotly中绘图区域上方的位置标题

python - 如何使用 slider 向 Plotly 条形图添加交互式文本?