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)
only, all I get is
<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’m 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 cant use st.markdown
or st.write
directly as I am using st.dataframe
to display