How to display a clickable link pandas dataframe

This is probably the best idea. Apparently, it can also be done using Ag-Grid (check the related issue here).


Another option is to render the dataframe as a plotly table, as it allows for some basic HTML like hyperlinks.

plotlytable

Code:
import streamlit as st
import pandas as pd
import plotly.graph_objects as go

def create_link(url:str) -> str:
    return f'''<a href="{url}">đź”—</a>'''

df = pd.DataFrame(
    {"Site": "DuckDuckGo Google Bing".split(),
     "URL": "https://duckduckgo.com/ https://www.google.com/ https://www.bing.com/".split()}
)

df['Link'] = [create_link(url) for url in df["URL"]]

"# Dataframe as a plotly table"

fig = go.Figure(
    data=[
        go.Table(
            columnwidth = [1,1,0.5],
            header=dict(
                values=[f"<b>{i}</b>" for i in df.columns.to_list()],
                fill_color='pink'
                ),
            cells=dict(
                values=df.transpose()
                )
            )
        ]
    )
st.plotly_chart(fig, use_container_width=True)
2 Likes