I’m trying to figure out how to create a Hyperlink in a table, and I use LinkColumn() to enable it, but I’m not using a simple dict, I want that the data inserted come from an xlsx sheet. What I already tried was to convert the object to a dict with “df.to_dict(orient=‘index’)” and now I have my dictionary, but I can’t enable the link between the “Name” and the desired URL. Below I’ll show you an example of the data and the desired output:
Here is the dict i got when I use df.to_dict(orient=‘index’):
{
"app1":{
"Description": "this is the app1"
"Official Website": "https://myapp.domain.com/home"
}
"app2":{
"Description": "this is the app2"
"Official Website": "https://myapp2.domain.com/home"
}
"app3":{
"Description": "this is the app3"
"Official Website": "https://myapp3.domain.com/home"
}
}
Now, the desired output should be
Here is a piece of my code:
import streamlit as st
import pandas as pd
# ------------ Configuration ----------- #
EXCEL_FILE_PATH = "path/to/sheet.xlsx"
def display_table(sheet_name):
cols_to_read = ['Tool Name', 'Description', 'Official Website']
df = pd.read_excel(
EXCEL_FILE_PATH,
sheet_name=sheet_name,
usecols=cols_to_read,
skiprows=2,
index_col=None
)
st.subheader("Tools and Resources")
df_for_dict = df.set_index('Tool Name')
tools_data_dict = df_for_dict.to_dict(orient='index')
st.write(tools_data_dict)
st_column_config = {}
if 'Tool Name' in df.columns and 'Official Website' in df.columns:
st_column_config["Tool Name"] = st.column_config.LinkColumn(
"Tool Name", # Header for this column in Streamlit
display_text="%(Tool Name)s", # Display the text from 'Tool Name' column
)
st_column_config["Official Website"] = None
else:
st.warning("Could not configure 'Tool Name' as a link. "
"Make sure 'Tool Name' and 'Official Website' columns exist in your Excel.")
st.dataframe(
df,
column_config=st_column_config,
hide_index=True,
use_container_width=True
)`
Preformatted text`
As you can see I want to link the column Tool Name to the column Official Website to create the Hyperlink, is there a way to do that? if not, what would you suggest in order to get the desired output? Thanks in advance