I am using data editor and passing the data and generating the table fine. One of the columns is going to be a hyperlink to get more information about the row. I was wondering if it is possible to edit the data to create your link. I.E Data is a list of id’s (1,2,3 etc.) and by default the editor adds to the end of the url like www.myapp.com/{id}, is it possible to change it so it can be something like www.myapp.com/something={id}
Or is it possible to merge two columns into one? Have one column be the correct link and the second column be the correct display. Don’t see if this is possible in the documentation.
import streamlit as st
import pandas as pd
if "df" not in st.session_state:
st.session_state.df = pd.DataFrame({"x": [1, 2, 3]})
st.session_state.df["link"] = (
"https://www.myapp.com/something/" + st.session_state.df["x"].astype(str)
)
out = st.data_editor(
st.session_state.df,
column_config={"link": st.column_config.LinkColumn(disabled=True)},
hide_index=True,
num_rows="dynamic",
)
if (
not out["link"].equals("https://www.myapp.com/something/" + out["x"].astype(str))
and not out["x"].isna().any()
):
st.write("changed")
out["link"] = "https://www.myapp.com/something/" + out["x"].astype(str)
st.session_state.df = out
st.rerun()
Thanks, this seems to work for data editor not but not for dataframes. Turns out I don’t really need the editing portion of data_editor for this page I am working on. I was able to manipulate the data to just do a path instead of the full URL. But my issue now is that I cannot get the display value to display what I actually want instead of the path that is currently being displayed. I also do not want to convert to html because that removes some functionality(mainly sorting).
Can you clarify exactly what you’re trying to have in the dataframe, and what you would like to see displayed? I think you will be able to accomplish it with st.column_config.LinkColumn - Streamlit Docs
So the value is not a Full URL. It’s just a string that adds to the end of the URL. (don’t have full domain yet so just working locally). The value is a subdirectory that I need to go to. But the Label I want to display on the dataframe to the users is something else.
Ex. The value I am passing to the dataframe is ‘/grant_info?Grant_name=name&grant_id=1’. I want the Label(display value) to be a combination of the {Grant_name} and the {Grant_Id}.
Sorry, I believe I wasn’t super clear with what I wanted to do on my end. My issue is now the display name, I was able to modify the data getting passed in to pass in the string I wanted. My issue is trying to manipulate the display name so it will show something more user friendly. my data is something like this “/Grant_info?grant_id=1&user_rest=0” What I want displayed is “Grant {Grand_id}” is so in the example above it would be Grant 1.
I tried something like above code. but I believe that type of formating only works with complete urls. Because nothing changes visually on my end. So I would have to use the panda style formater?
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.