Display the 2nd page from a link in the search result in the current output of Streamlit


I am working locally with streamlit. I’m using strealmit to query my search engine and get the result back. I send a query to the search engine and convert the result set into a dataframe and write this dataframe

 st.write(search_result_df.to_html(escape = **False** , index=**True** ), unsafe_allow_html = **True** )


When I run the streamlit, the above UI showed up. The first column is a hyperlink (ID) which I would like to click and call a Python script that takes that ID, calls a rest API for that ID, and return some result back and show that result on the page.

Thanks in advance for your help

Here’s a slightly different approach, that adds a boolean column and a dataframe editor which lets you click on a row and get the id from that, and then resets the editor so that you can only select at most one row at a time:

import streamlit as st
import pandas as pd

    "patent_id": ["US-123", "US-456", "US-789", "US-101"],
    "description": [
        "Some description",
        "Some description",
        "Some description",
        "Some description",

ID_COL = "patent_id"

if "data" not in st.session_state:
    st.session_state["data"] = pd.DataFrame(
            "select": [False, False, False, False],

if "editor_id" not in st.session_state:
    st.session_state["editor_id"] = 0

if "last_selected" not in st.session_state:
    st.session_state["last_selected"] = None

def edited():
    editor_state = st.session_state[st.session_state["editor_id"]]

    selected_row, state = list(editor_state["edited_rows"].items())[-1]
    st.session_state["data"]["select"] = False
    if not state["select"]:
        st.session_state["last_selected"] = None

    selected_id = st.session_state["data"].loc[selected_row, ID_COL]
    st.session_state["last_selected"] = selected_id
    st.session_state["data"].loc[selected_row, "select"] = True
    st.session_state["editor_id"] += 1

    column_config={ID_COL: st.column_config.Column(disabled=True)},

st.write("Last selected id", st.session_state["last_selected"])

Thanks and sorry for late replay.
Yes it works fine :slight_smile:

I just have another question about the text format in data_editor. the long texs are presented as one row. Is there any option with “data_editor” to format output ( wrap text) like this: st.markdown(df.to_html(escape=False), unsafe_allow_html=True)

Thank you

I don’t believe there’s any way to do that, no

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