When I follow the given pattern, but use it on a pd.Styler object instead of a pd.DataFrame, the LinkColumn seems to just be ignored. Instead of displaying just the portion of text defined in the regex “(.*?)” and making it a hyperlink, I am seeing the full link text and it is just displaying as a string.
Is this expected behavior or is there something I am missing?
If this is expected, I would request allowing the links in a Styler - it helps immensely to have a stylized DataFrame since it helps with the user experience.
My Streamlit version is 1.31.0, I am running it through a private AWS server using python 3.10.12.
If you decide to manually embed links, you’d typically have to convert your DataFrame to HTML and then insert that HTML into st.markdown.
import streamlit as st
import pandas as pd
df = pd.DataFrame({
'Name': ['Item 1', 'Item 2'],
'URL': ['http://example.com/1', 'http://example.com/2']
})
df['Linked Name'] = df.apply(lambda x: f'<a href="{x["URL"]}">{x["Name"]}</a>', axis=1)
html = df.to_html(escape=False, index=False)
st.markdown(html, unsafe_allow_html=True)
This method directly embeds HTML links into the DataFrame, but it bypasses the pd.Styler and LinkColumn Streamlit functionality, limiting the approach to static displays.
Thanks both for the additional info and supplying other methods of getting the links to work
That being said, I’ll probably put in an issue on this in GitHub (or see if one is already there) - it seems like the ideal functionality would be to have links available in a first class way while using a styler object
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.