Python 用“;href”;不使用本地相对html路径

Python 用“;href”;不使用本地相对html路径,python,plotly,plotly-dash,plotly-python,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

我有一个简单的表格,里面有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")

更新:

以下链接部分起作用

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

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

您可以在浏览器中禁用此安全检查或使用扩展名

将plotly.express导入为px
df=px.data.gapminder().query(“年份==2007”)
链接_ref=“”
df['country']=df['country'].应用(lambda项目:链接参考格式(项目))
fig=px.treemap(df,路径=['大陆','国家'],值='流行',
color='lifeExp',hover_data=['iso_alpha'])
fig.write_html(“index.html”)

您正在使用jupyter笔记本?不,我没有使用Jupter nootbook和dash。请尝试在
href
属性中提供html文件的绝对路径。绝对路径似乎对我也不起作用。我觉得奇怪的一件事是你有
link\u-ref.format(item)
,但是
link\u-ref
没有任何格式说明符,所以这不起任何作用,而且你的
标记中没有任何内容,你可能想要
{}
那么文本会被插入到标签中吗?
link_ref = '<a href="http:///files/file1.html">{}</a>'
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")