# Is it possible to customize Link in data\_editor

**URL:** <https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704>\
**Category:** Using Streamlit\
**Tags:** data\_editor, discussion\
**Created:** [April 23, 2024, 4:44pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704 "2024-04-23T16:44:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![elsuenog](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/elsuenog/32/42084_2.png) [@elsuenog](https://discuss.streamlit.io/u/elsuenog)\
**Post date:** [April 23, 2024, 4:44pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/1 "2024-04-23T16:44:50Z")

</div>

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}](http://www.myapp.com/%7Bid%7D), is it possible to change it so it can be something like [www.myapp.com/something={id}](http://www.myapp.com/something=%7Bid%7D)

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.

---

<div class="post-metadata">

**Author:** ![blackary](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/blackary/32/47725_2.png) [@blackary](https://discuss.streamlit.io/u/blackary)\
**Post date:** [April 24, 2024, 7:07pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/2 "2024-04-24T19:07:25Z")

</div>

Hi @elsuenog, welcome to the forum!

Here’s one way to do it

```python
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()

```

---

<div class="post-metadata">

**Author:** ![elsuenog](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/elsuenog/32/42084_2.png) [@elsuenog](https://discuss.streamlit.io/u/elsuenog)\
**Post date:** [April 24, 2024, 7:39pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/3 "2024-04-24T19:39:57Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![blackary](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/blackary/32/47725_2.png) [@blackary](https://discuss.streamlit.io/u/blackary)\
**Post date:** [April 26, 2024, 1:38pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/4 "2024-04-26T13:38:15Z")

</div>

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](https://docs.streamlit.io/develop/api-reference/data/st.column_config/st.column_config.linkcolumn)

---

<div class="post-metadata">

**Author:** ![elsuenog](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/elsuenog/32/42084_2.png) [@elsuenog](https://discuss.streamlit.io/u/elsuenog)\
**Post date:** [April 29, 2024, 6:38pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/5 "2024-04-29T18:38:50Z")

</div>

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}.

---

<div class="post-metadata">

**Author:** ![blackary](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/blackary/32/47725_2.png) [@blackary](https://discuss.streamlit.io/u/blackary)\
**Post date:** [April 30, 2024, 3:16pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/6 "2024-04-30T15:16:06Z")

</div>

I would recommend doing what I did, then, just with 2 plusses to combine all the parts of the url:

```auto
st.session_state.df["link"] = (
      "/grant_info?grant_name=" + st.session_state.df["grant_name"].astype(str) + "&grant_id=" + st.session_state.df["grant_id"].astype(str)
  )

```

---

<div class="post-metadata">

**Author:** ![elsuenog](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/elsuenog/32/42084_2.png) [@elsuenog](https://discuss.streamlit.io/u/elsuenog)\
**Post date:** [May 1, 2024, 2:45pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/7 "2024-05-01T14:45:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elsuenog](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/elsuenog/32/42084_2.png) [@elsuenog](https://discuss.streamlit.io/u/elsuenog)\
**Post date:** [May 1, 2024, 2:47pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/8 "2024-05-01T14:47:42Z")

</div>

```auto
         "grant_name": st.column_config.LinkColumn(
            "Grant Name",
            display_text="/Grant_info?grant_id=(.*?)&user_rest=0"
        ),  

```

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?

---

<div class="post-metadata">

**Author:** ![blackary](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/blackary/32/47725_2.png) [@blackary](https://discuss.streamlit.io/u/blackary)\
**Post date:** [May 7, 2024, 9:27pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/9 "2024-05-07T21:27:47Z")

</div>

Ah, that makes sense – it looks your example works if you escape the first ?

```auto
df = pd.DataFrame(
    {
        "grant_name": [
            "/Grant_info?grant_id=1&user_rest=0",
            "/Grant_info?grant_id=2&user_rest=0",
            "/Grant_info?grant_id=3&user_rest=0",
        ],
    }
)

st.dataframe(
    df,
    column_config={
        "grant_name": st.column_config.LinkColumn(
            "Grant Name",
            display_text="/Grant_info\?grant_id=(.*?)&user_rest=0",
        )
    },
)

```

![image](https://global.discourse-cdn.com/streamlit/original/3X/d/8/d8f44dbbf104111c255573ecb486e7189ada29e5.png)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [November 3, 2024, 9:28pm UTC](https://discuss.streamlit.io/t/is-it-possible-to-customize-link-in-data-editor/67704/10 "2024-11-03T21:28:02Z")

</div>

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