python - Plotly:带有“href”的树形图元素不起作用
问题描述
我href
在文本中有简单的表格 whin 链接。但是点击它不会打开页面。有什么简单的方法可以做到这一点?
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()
推荐阅读
- python - 为什么来自 Tensorflow 2 对象检测 API 的微调模型上的 mAP 较低?
- python - 有没有办法在类的 init() 函数中设置一个 elif 语句?
- android - 为什么我的 Activity 语言在 Android 8 之前的设备上没有改变?
- git - 如何停止 git difftool?
- c# - 无法使用 IDataReader 读取临时表
- python-3.x - 错误的错误名称“文件”可以在 python pycharm 中未定义
- memcached - 如何在 Azure 上使用 memcached 云
- python - x 轴上的分组条形图
- python - 如何解决 Python 中的 ValueError?
- node.js - 在 node.js 中发出 api 请求并在函数调用者中获取响应的问题