import streamlit as st import time # def submit_callback(): # st.session_state.clicked = False # handle the user_input here # st.write("Product: " + st.session_state.product) # st.write("Gender: " + st.session_state.gender) # st.write("Profession: " + st.session_state.profession) # st.write("Hobby: "+ st.session_state.hobby) col1, col2=st.columns(2) with col1: with st.container(height=500): with st.form("my_input", clear_on_submit=True, border=False): st.write("Input") # product product=st.text_input("product", key="product") # gender gender=st.radio("gender", ["male", "female", "Non-binary"], key="gender") # profession profession=st.text_input("profession", key="profession") # hobby hobby=st.text_input("hobby", key="hobby") # Every form must have a submit button. # submitted = st.form_submit_button(label='Submit', on_click=submit_callback) submitted = st.form_submit_button(label='Submit') with col2: if submitted: with st.spinner('Wait for it...'): time.sleep(5) with st.container(height=500): placeholder = st.empty() # Replace the chart with several elements: with placeholder.container(): st.write("Product: " + st.session_state.product) st.write("Gender: " + st.session_state.gender) st.write("Profession: " + st.session_state.profession) st.write("Hobby: "+ st.session_state.hobby) if 'clicked' not in st.session_state: st.session_state.clicked = False def click_button(): st.session_state.clicked = True st.button('Clear', on_click=click_button) if st.session_state.clicked: # The message and nested widget will remain on the page del st.session_state.product del st.session_state.gender del st.session_state.profession del st.session_state.hobby del st.session_state.clicked if submitted: placeholder.empty() # Clear all those elements: # placeholder.empty() # if clear: # del st.session_state.product # del st.session_state.gender # del st.session_state.profession # del st.session_state.hobby # placeholder.empty() # container1 = st.container(border=True) # col1, col2 = st.columns(2) # with col1: # container1 = col1.container(height=3000, ) # with col2: # container2 = col2.container(height=300) # placeholder = st.empty() # placeholder = st.empty() # # Create two columns # col1, col2 = st.columns(2) # # Place a form in each column # with col1: # def submit_callback(): # st.write("Product: " + st.session_state.product) # st.write("Gender: " + st.session_state.gender) # st.write("Profession: " + st.session_state.profession) # st.write("Hobby: "+ st.session_state.hobby) # def delete_callback(): # del st.session_state.product # del st.session_state.gender # del st.session_state.profession # del st.session_state.hobby # placeholder.empty() # import streamlit as st # import time # class SessionState: # def __init__(self): # self.product = "" # self.gender = "" # self.profession = "" # self.hobby = "" # state = SessionState() # def submit_callback(): # with output_placeholder.container(): # st.write("Product: " + state.product) # st.write("Gender: " + state.gender) # st.write("Profession: " + state.profession) # st.write("Hobby: "+ state.hobby) # def delete_callback(): # state.product = "" # state.gender = "" # state.profession = "" # state.hobby = "" # output_placeholder.empty() # form_placeholder = st.empty() # output_placeholder = st.empty() # submitted = False # clear = False # with form_placeholder.form("my_form", clear_on_submit=True): # st.write("Input") # # product # state.product = st.text_input("product", value=state.product, key="product") # # gender # state.gender = st.radio("gender", ["male", "female"], value=state.gender, key="gender") # # profession # state.profession = st.text_input("profession", value=state.profession, key="profession") # # hobby # state.hobby = st.text_input("hobby", value=state.hobby, key="hobby") # # Every form must have a submit button. # btn1, btn2=st.columns(2) # with btn1: # submitted = st.form_submit_button(label='Submit') # with btn2: # clear = st.form_submit_button(label='Clear') # if clear: # delete_callback() # if submitted: # submit_callback() # def submit_callback(): # with output_placeholder.container(): # st.write("Product: " + st.session_state.product) # st.write("Gender: " + st.session_state.gender) # st.write("Profession: " + st.session_state.profession) # st.write("Hobby: "+ st.session_state.hobby) # def delete_callback(): # del st.session_state.product # del st.session_state.gender # del st.session_state.profession # del st.session_state.hobby # output_placeholder.empty() # form_placeholder = st.empty() # output_placeholder = st.empty() # with form_placeholder.form("my_input", clear_on_submit=True): # st.write("Input") # # product # product=st.text_input("product", key="product") # # gender # gender=st.radio("gender", ["male", "female"], key="gender") # # profession # profession=st.text_input("profession", key="profession") # # hobby # hobby=st.text_input("hobby", key="hobby") # # Every form must have a submit button. # btn1, btn2=st.columns(2) # with btn1: # submitted = st.form_submit_button(label='Submit', on_click=submit_callback) # # submitted = st.form_submit_button(label='Submit') # with btn2: # clear = st.form_submit_button(label='Clear', on_click=delete_callback) # if submitted: # # handle the user_input here # st.write("Product: " + st.session_state.product) # st.write("Gender: " + st.session_state.gender) # st.write("Profession: " + st.session_state.profession) # st.write("Hobby: "+ st.session_state.hobby) # if clear: # del st.session_state.product # del st.session_state.gender # del st.session_state.profession # del st.session_state.hobby # placeholder.empty() # # with col2: # _LOREM_IPSUM = ( # "product" + str(st.session_state.product) + "\n" # + "gender" + str(st.session_state.gender) + "\n" # + "profession" + str(st.session_state.profession) + "\n" # + "hobby" + str(st.session_state.hobby) +"\n" # ) # def stream_data(): # for word in _LOREM_IPSUM.split(" "): # yield word + " " # time.sleep(0.02) # if st.button("Stream data"): # st.write_stream(stream_data) # placeholder = st.empty() # with placeholder.container(): # st.write("Hello") # import streamlit as st # class SessionState: # def __init__(self): # self.input_text = "" # state = SessionState() # with st.form("my_form"): # state.input_text = st.text_input("Enter something:", value=state.input_text) # clear_button = st.form_submit_button("Clear") # submit_button = st.form_submit_button("Submit") # if clear_button: # state.input_text = "" # if submit_button: # # handle the user_input here # st.write(f"You submitted: {state.input_text}") # import streamlit as st # import time # class SessionState: # def __init__(self): # self.product = "" # self.gender = "" # self.profession = "" # self.hobby = "" # state = SessionState() # def submit_callback(): # output_placeholder.write("Product: " + state.product) # output_placeholder.write("Gender: " + state.gender) # output_placeholder.write("Profession: " + state.profession) # output_placeholder.write("Hobby: "+ state.hobby) # def delete_callback(): # state.product = "" # state.gender = "" # state.profession = "" # state.hobby = "" # output_placeholder.empty() # form_placeholder = st.empty() # output_placeholder = st.empty() # with form_placeholder.form("my_form"): # st.write("Input") # # product # state.product = st.text_input("product", value=state.product, key="product") # # gender # state.gender = st.radio("gender", ["male", "female"], value=state.gender, key="gender") # # profession # state.profession = st.text_input("profession", value=state.profession, key="profession") # # hobby # state.hobby = st.text_input("hobby", value=state.hobby, key="hobby") # # Every form must have a submit button. # btn1, btn2=st.columns(2) # with btn1: # submitted = st.form_submit_button(label='Submit') # with btn2: # clear = st.form_submit_button(label='Clear') # if clear: # delete_callback() # if submitted: # # handle the user_input here # submit_callback() # _LOREM_IPSUM = """ # Lorem ipsum dolor sit amet, **consectetur adipiscing** elit, sed do eiusmod tempor # incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis # nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. # """ # def stream_data(): # for word in _LOREM_IPSUM.split(" "): # yield word + " " # time.sleep(0.02) # for word in _LOREM_IPSUM.split(" "): # yield word + " " # time.sleep(0.02) # if st.button("Stream data"): # st.write_stream(stream_data) # import streamlit as st # import SessionState # from streamlit.server.server import Server # import streamlit.report_thread as ReportThread # # Initialize session state # session_state = SessionState.get(product="", gender="", profession="", hobby="") # # Create a form for user inputs # with st.form("my_input"): # st.write("Input") # # product # product = st.text_input("product", value=session_state.product) # # gender # gender = st.radio("gender", ["male", "female"], index=["male", "female"].index(session_state.gender) if session_state.gender else 0) # # profession # profession = st.text_input("profession", value=session_state.profession) # # hobby # hobby = st.text_input("hobby", value=session_state.hobby) # # Every form must have a submit button. # submitted = st.form_submit_button("Submit") # clear = st.form_submit_button("Clear") # # Display the user inputs # with st.form("my_output"): # if submitted and not clear: # # Save inputs to session state # session_state.product = product # session_state.gender = gender # session_state.profession = profession # session_state.hobby = hobby # st.write("product", product) # st.write("gender", gender) # st.write("profession", profession) # st.write("hobby", hobby) # # Clear the user inputs # if clear: # # Clear session state # session_state.product = "" # session_state.gender = "" # session_state.profession = "" # session_state.hobby = "" # st.experimental_rerun()