def main():
if "data" not in st.session_state:
st.session_state.data = {
"person_locations": [],
"organization_num_employees_ranges": [],
"person_titles": [],
"q_organization_keyword_tags": []
}
page = st.sidebar.selectbox("Choose a page", ["Customize Parameters", "Results Page","Final Page"])
if page == "Customize Parameters":
st.title("Customize Parameters")
# Person locations
person_locations = st.multiselect("Select Person Locations", country_names,
default=st.session_state.data["person_locations"])
# Organization number of employees ranges
organization_num_employees_ranges = st.multiselect("Select Organization Number of Employees Ranges",
["1,10", "11,20", "21,50", "51,100", "101,200",
"201,500", "501,1000", "1001,2000", "2001,5000",
"5001,10000", "10001+"],
default=st.session_state.data["organization_num_employees_ranges"])
# Person titles
entered_titles = st.text_area("Enter Person Titles (comma-separated)",
value=", ".join(st.session_state.data["person_titles"]))
person_titles = [title.strip() for title in entered_titles.split(",") if title.strip()]
# Organization keyword tags
q_organization_keyword_tags = st.text_input("Enter Organization Keywords (comma-separated)",
value=", ".join(st.session_state.data["q_organization_keyword_tags"]))
q_organization_keyword_tags = [tag.strip() for tag in q_organization_keyword_tags.split(",")]
st.session_state.data["person_locations"] = person_locations
st.session_state.data["organization_num_employees_ranges"] = organization_num_employees_ranges
st.session_state.data["person_titles"] = person_titles
st.session_state.data["q_organization_keyword_tags"] = q_organization_keyword_tags
if st.button("Submit"):
st.session_state.data_submitted = True
st.success("Data submitted successfully!")
st.markdown("[Go to Result Page](#result)")
elif page == "Results Page":
if "data_submitted" in st.session_state and st.session_state.data_submitted:
st.title("Result Page")
df = pd.DataFrame({
'First Name': [person.get('first_name', '') for person in mde],
'Last Name': [person.get('last_name', '') for person in mde],
'LinkedIn URL': [person.get('linkedin_url', '') for person in mde],
'Title': [person.get('title', '') for person in mde],
'Headline': [person.get('headline', '') for person in mde],
"Grab Emails?": False
})
st.data_editor(
df, width=2000,
column_config={
"Grab Emails?": st.column_config.CheckboxColumn(
"Grab Emails?",
help="Tick to grab emails. This will consume 2 credit per email",
default=False,
)
},
disabled=["First Name","Last Name","LinkedIn URL","Title","Headline","Email"],
hide_index=True, key = 'dfdata1'
)
# Button to navigate to Final Page
if st.button('Go to Final Page'):
st.session_state.page = "Final Page"
st.experimental_rerun() # Rerun the app to reflect the updated state
else:
st.warning("Please submit the data first from the Customize Parameters page.")
elif page == "Final Page":
# Your Page 3 content goes here
st.title("Final Page")
st.write("Content of Final Page")
if __name__ == "__main__":
main()
With regards to the dataframe df that I have on the Results Page, I would like to create another df below it that filters for rows in df where the checkbox in column “Grab Emails?” is ticked (i.e. TRUE).
How can I do this? I have tried to do df[df[‘Grab Emails?’]] but this doesn’t generate any rows (i.e. it is saying there are no rows in the column that are TRUE).
I am running this script locally.