带有“href"的绘图树图元素不适用于本地相对 html 路径 [英] plotly treemap element with “href” not working with local relative html paths

查看:69
本文介绍了带有“href"的绘图树图元素不适用于本地相对 html 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

文件夹结构如下.因为root会变,所以需要相对路径.

--root--root/index.html--root/files/file1.html--root/files/file2.html导入 plotly.express 作为 pxdf = 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=[ '大陆', '国家'], values='pop',color='lifeExp', hover_data=['iso_alpha'])fig.write_html("index.html")

注意:以 http 开头的链接有效.

更新:

以下链接部分有效.

link_ref = '{}'

解决方案

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

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

import plotly.express as pxdf = 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=[ '大陆', '国家'], values='pop',color='lifeExp', hover_data=['iso_alpha'])fig.write_html("index.html")

I have simple table with href inside the text. The href points to relative path of local html file. But clicking on it doesn't open the page. is there any way to do that/ good workaround?

The folder structure is following. As the root will be changed, so the relative path is needed.

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

Note: The link starting with http works. Plotly: treemap element with "href" not working

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

Update:

The following link partially works.

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

解决方案

File links are an issue for security reasons. I tested this code with IE 11 and it worked fine, no issues. For Firefox, Chrome, and Edge it does not work.

You may be able to disable this security check in your browser or use an extension. 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")

这篇关于带有“href"的绘图树图元素不适用于本地相对 html 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆