I have a pandas dataframe containing clickable links. In jupyter notebook, it displays a dataframe with clickable links that directs me corresponding directories as shown below:
However, when I try to run display the dataframe in streamlit, it wouldn’t render html and does not show the clickable link as shown below:
One way would be to use the to_html method in pandas and combine it with Streamlit’s options for injecting html. Though this would lose the interactivity of the pandas dataframe and make it a static table.
I see in the documentation that there is experimental support for pandas styler, but I don’t know off the bat how it behaves with styling links since Streamlit is a bit specific about how it accepts and displays html. I’m playing around with it right now and will post again if I find something.
Thanks for your suggestion here. I’d like to make my table interactive and Ag-Grid seems like the option here, but I’ve never used it before. According to the reference you shared, it looks like it’s using Ag-Grid and importing javascript function to make the values in a specific column clickable. Do you happen to have a working example that would work in this example? Thanks so much for your help
You are right. A JsCode instance is passed to the cellRendered kwarg. The JsCode is just a JS function that takes the content in the column and builds an HTML hyperlink tag:
With the latest Streamlit release (1.23) we added new column types that can be used with st.dataframe or st.data_editor. This also includes the LinkColumn which can just URLs as clickable hyperlinks:
import pandas as pd
import streamlit as st
data_df = pd.DataFrame(
{
"apps": [
"https://roadmap.streamlit.app",
"https://extras.streamlit.app",
"https://issues.streamlit.app",
"https://30days.streamlit.app",
],
}
)
st.data_editor(
data_df,
column_config={
"apps": st.column_config.LinkColumn("Trending apps")
},
hide_index=True,
)
It’s currently not possible to show a label instead of the URL, if you would like to do that as well you can upvote this feature request on Github.
Just updating this thread, it is possible now (version 1.30) to show a label instead of the URL . column_config.LinkColumn takes the display_text parameter to format the text that is displayed in the cell.
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.