0

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

vestland
  • 55,229
  • 37
  • 187
  • 305
Oli
  • 1,313
  • 14
  • 31

1 Answers1

1

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()
rpanai
  • 12,515
  • 2
  • 42
  • 64
  • Thanks it works, one side question, how to give relatvie path to local html file? e.g `link_ref = '{}'`. Unfortunatelly this doesn't work. – Oli Jul 18 '20 at 09:58
  • 1
    Could you also look into following. https://stackoverflow.com/questions/62967338/plotly-treemap-element-with-href-not-working-with-local-relative-html-paths – Oli Jul 20 '20 at 11:11