I am attempting to display a clickable hyperlink inside a dataframe containing filtered results on Streamlit. This is my code so far:
import pandas as pd
import streamlit as st
import openpyxl
import numpy as np
from IPython.core.display import display, HTML
df = pd.read_excel(
io='list.xlsx',
engine= 'openpyxl',
).fillna('')
def make_clickable(link):
# target _blank to open new window
# extract clickable text to display for your link
text = link.split('=')[0]
return f'<a target="_blank" href="{link}">{text}</a>'
# TRAILER is the column with hyperlinks
df['TRAILER'] = df['TRAILER'].apply(make_clickable)
df['TRAILER'] = HTML(display(df.to_html(render_links=True, escape=False), raw=True))
If I use:
df['TRAILER'] = df['TRAILER'].apply(make_clickable)
I get
<a target="_blank" href="{link}">{text}</a>
displayed as a string but not a hyperlink.
When I add:
df['TRAILER'] = HTML(display(df.to_html(render_links=True, escape=False), raw=True))
I get:
<IPython.core.display.HTML object>
displayed as a string but not a hyperlink.
These are the versions I am using. Other components of the site work only with a lower version of Streamlit which is why I am using this version.
streamlit == 0.83 numpy == 1.18 pandas == 1.2 openpyxl ipython == 7.22 python == 3.9
I cannot use st.markdown
or st.write
directly as I am using st.dataframe
to display the results.