create a streamlit application, one drop-box field, and one button. Put randon data in the drop-box. The action, after pressing the button, show the selection and cleanup the selected value from the drop-box to start over
To upload files, please first save the app
import streamlit as st
import random
# Initialize session state for the options if not exists
if 'options' not in st.session_state:
st.session_state.options = [
"Red Apple",
"Blue Sky",
"Green Grass",
"Yellow Sun",
"Purple Mountains",
"Orange Sunset",
"Pink Flowers",
"Brown Earth"
]
st.title("Selection and Cleanup Demo")
# Create the dropdown
selected_item = st.selectbox(
"Choose an item:",
st.session_state.options,
index=None,
placeholder="Select an item..."
)
# Create the button
if st.button("Show and Clear Selection"):
if selected_item:
st.success(f"You selected: {selected_item}")
# Remove the selected item from the options
st.session_state.options = [opt for opt in st.session_state.options if opt != selected_item]
# Rerun the app to update the dropdown
st.rerun()
else:
st.warning("Please select an item first!")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?