【问题标题】:How to add (clickable) hyperlinks to a Sunburst in Plotly without using Dash?如何在不使用 Dash 的情况下向 Plotly 中的 Sunburst 添加(可点击的)超链接?
【发布时间】:2023-02-03 15:47:32
【问题描述】:

我需要将某些 URL 链接添加到 Sunburst 的某些部分,类似于此示例。

我已经研究这个问题一段时间了,但找不到仅使用 Plotly 的解决方案——是否有可能使用 Plotly 或 Plotly express 使这些链接可点击?

import pandas as pd
import plotly.express as px

data = {'site': {1: 'Site 1', 2: 'Site 2', },
        'link': {1: 'http://www.google.com', 2: 'http://www.facebook.com'},
        'popularity': {1: 50, 2: 50}}

df = pd.DataFrame(data)

fig = px.sunburst(df,
                  path=['site', 'link'],
                  values='popularity',
                  maxdepth=2,)

fig.show()

【问题讨论】:

    标签: python hyperlink plotly sunburst-diagram plotly-express


    【解决方案1】:

    添加 .html 使其工作。

    import pandas as pd
    import plotly.express as px
    
    data = {'site': {1: 'Site 1', 2: 'Site 2', },
            'link': {1: '<a href="http://www.google.com">link text</a>', 2: 'http://www.facebook.com'},
            'popularity': {1: 50, 2: 50}}
    
    df = pd.DataFrame(data)
    
    fig = px.sunburst(df,
                      path=['site', 'link'],
                      values='popularity',
                      maxdepth=2,)
    
    fig.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 2013-02-24
      • 2021-03-04
      相关资源
      最近更新 更多