Links in st.dataframe with styler

I just started trying to use the new functionality of including links in a streamlit dataframe (st.column_config.LinkColumn - Streamlit Docs).

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.

Hi @msquaredds

It seems that pandas styler may be used with st.table and may conflict with column_config if used on st.dataframe.

Please see the following relevant forum posts:

Hello @msquaredds,

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.

Kind Regards,
Sahir

P.S. Lets connect on LinkedIn!

1 Like

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

1 Like

In case anyone else finds this, the link to a pre-existing issue on GitHub is here:

https://github.com/streamlit/streamlit/issues/7977

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

Great idea and implementation @sahirmaharaj

1 Like