Streamit delete a form row attempt
Mon Jan 16 2023 05:37:32 GMT+0000 (Coordinated Universal Time)
Saved by
@tofufu
#python
#streamlit
import streamlit as st
from streamlit import session_state as ses
if "num_cases" not in ses:
ses["num_cases"] = 3
delete_part = st.container()
if st.button("Add a row"):
ses["num_cases"] += 1
cols = st.columns((1, 2))
for i in range(0, ses["num_cases"]):
cols[1].write("")
cols[1].write("")
delete = cols[1].button(label="X", key="delete_" + str(i+1))
with delete_part:
st.write("delete")
if delete:
st.write("pressed")
ses["num_cases"] -= 1
st.write("text_" + str(i+1))
cols[0].empty()
cols[1].empty()
del ses["text_" + str(i+1)]
try:
cols[0].text_input(label="Row " + str(i+1), key="text_" + str(i+1))
except:
pass
deletion = st.empty()
deletion.text_input(label="testing removability", key="removable")
if st.button("delete"):
deletion.empty()
del ses["removable"]
st.write(ses)
content_copyCOPY
Comments