我有一个简单的表格,文本内有 href 。 href指向本地html文件的相对路径。
但点击它并不会打开该页面。有什么办法可以做到这一点/好的解决方法吗?
文件夹结构如下。由于root会改变,所以需要相对路径。
--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
works. Plotly:带有“href”的树形图元素不起作用 https://stackoverflow.com/questions/62955631/plotly-treemap-element-with-href-not-working/62961999#62961999
link_ref = '<a href="http://google.com">{}</a>'
Update:
以下链接部分有效。
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 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")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)