Hi,
I am looking for a solution to use multiple buttons and save the edit changes in session state.
import streamlit as st
from collections import defaultdict
import SessionState
state = SessionState.get(rerun=False, view_more=dict())
contents =[{"content_id": 23402, 'title': "hello world"},
{"content_id": 45463, "title": "hello streamlit"}]
bns = defaultdict(dict)
def init_bns(i):
st.write(contents[i])
bns[i][0] = st.button("view more", key=i)
bns[i][1] = st.empty()
bns[i][2] = st.empty()
bns[i][3] = st.empty()
state.view_more[i] = False
def edit_form(i):
if bns[i][0]:
state.view_more[i] = True
if state.view_more[i]:
state.t1 = bns[i][1].text_input("edit text1")
state.t2 = bns[i][2].text_area("edit text2")
state.bb = bns[i][3].button("save")
if state.bb:
st.write("success!")
st.write(state.t1)
st.write(state.t2)
for i in range(len(contents)):
init(i)
if bns[i][0]:
edit_form(i)
when clicking the ‘view more’ button, the text input area is showed. But each time after inputing something and clicking enter, the whole edit area disappears. I’ve tried many ways, even without using a loop. I can make a single button version works according to this example: The button inside a button seems to reset the whole app.Why?, but stuck on more than one buttons case. Can anyone help with this?