Multiple links in one dataframe field

This was a great idea, so sharing here an example using st.dialog:

links_from_df

Code:
import streamlit as st
import pandas as pd


@st.experimental_dialog("Links")
def dialog_with_links(links: list[str]):
    for link in links:
        st.link_button(link, url=link)


data = [
    [
        "Search",
        "🔎",
        "https://www.google.com, https://duckduckgo.com/, https://www.bing.com",
    ],
    [
        "Version control",
        "⏲️",
        "https://www.github.com, https://gitlab.com, https://bitbucket.org",
    ],
    ["Tutorials", "🙋‍♂️", "https://www.python.org, https://realpython.com/"],
    [
        "Streamlit",
        "🎈",
        "https://stpyvista.streamlit.app, https://streamlit.io, https://discuss.streamlit.io/",
    ],
]

df = pd.DataFrame(data, columns=["Name", "Emoji", "link_list"])


def main():
    left_column, right_column = st.columns([2, 1])

    with left_column:
        "### Simple dataframe"

        st.dataframe(
            df,
            use_container_width=True,
            column_config={"link_list": st.column_config.ListColumn("Links")},
        )

    with right_column:
        "### Trigger a dialog with options"

        selection = st.dataframe(
            df,
            use_container_width=True,
            column_config={"link_list": None},
            hide_index=True,
            selection_mode="single-row",
            on_select="rerun",
        )

        if row := selection["selection"]["rows"]:
            links = df["link_list"].loc[row].values[0].split(",")
            dialog_with_links(links)


if __name__ == "__main__":
    main()
2 Likes