簡體   English   中英

Plotly:帶有“href”的樹形圖元素不起作用

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

我在文本中有簡單的表格 whin href鏈接。 但是點擊它不會打開頁面。 有什么簡單的方法可以做到這一點?

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

您只需要擺脫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