Select single or multiple rows in st.dataframe and return the selected data

My question is similar to below

but here i am fetching data from a link using submit button on sidebar. So after fetching the get populated on the app but as soon as i select any row both dataframes get deleted.

import streamlit as st
import pandas as pd

def load_data():
    return pd.read_csv(

def dataframe_with_selections(df):
    df_with_selections = df.copy()
    df_with_selections.insert(0, "Select", False)
    edited_df = st.data_editor(
        column_config={"Select": st.column_config.CheckboxColumn(required=True)},
    # Filter the dataframe using the temporary column
    selected_rows = edited_df[edited_df["Select"]]
    return selected_rows.drop("Select", axis=1)

def main():
    st.sidebar.title("Data Selection")
    if st.sidebar.button("Submit"):
        df = load_data()
        selection = dataframe_with_selections(df)
        st.write("Your selection:")

if __name__ == "__main__":

Then don’t put the code that shows the dataframes inside the if block.