简体   繁体   English

Plotly:带有“href”的树形图元素不起作用

[英]Plotly: treemap element with “href” not working

I have simple table whin href link inside the text.我在文本中有简单的表格 whin href链接。 But clicking on it doesn't open the page.但是点击它不会打开页面。 is there any easy way to do that?有什么简单的方法可以做到这一点?

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

link_ref = '<a xlink:href="http://google.com" style="cursor: pointer" target="_blank" rel="noopener noreferrer">{}</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.show()

You just need to get rid of xlink: The following should work您只需要摆脱xlink:以下应该可以工作

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

link_ref = '<a href="http://google.com" style="cursor: pointer" target="_blank" rel="noopener noreferrer">{}</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.show()

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

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