情节:带有“href"的树状图元素不工作 [英] Plotly: treemap element with "href" not working

查看:47
本文介绍了情节:带有“href"的树状图元素不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表格,文本中包含 href 链接.但是点击它不会打开页面.有没有什么简单的方法可以做到这一点?

import plotly.express as pxdf = px.data.gapminder().query("year == 2007")link_ref = '

解决方案

你只需要去掉 xlink: 以下应该可以工作

import plotly.express as pxdf = px.data.gapminder().query("year == 2007")link_ref = '

I have simple table whin href link inside the text. 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

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

这篇关于情节:带有“href"的树状图元素不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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