Hi,
I want to update a Dataframe that is right after my text input and the update button. But I can’t figure out how to keep this placement since the button condition for updating must be placed where I want my button to be placed… any clues ? Thank you in advance
colums = ["A","B","C"]
df = pd.DataFrame(columns=colums)
st.write("Add your numbers")
c1, c2, c3 = st.beta_columns((1,1,1))
T1 = c1.text_input("text1")
T2 = c2.text_input("text2")
T3 = c3.text_input("text3")
if(st.button('Add')):
add = []
T11 = int(T1.title())
T22 = int(T2.title())
T33 = int(T3.title())
add.append([T1,T2,T3])
df2 = pd.DataFrame(add, columns=colums)
mytable.add_rows(df2)
st.success("added")
mytable = st.table(df)
Hi @WBP2020 , welcome to the Streamlit community!
I’m afraid I don’t understand your question. You want to have an add button that adds rows to a dataframe, but after that I’m not sure I understand the issue.
Hi, thank you.
My problem is that the table I want to update must be below the button and inputs text !
But in the part
if(st.button('Add')):
add = []
T11 = int(T1.title())
T22 = int(T2.title())
T33 = int(T3.title())
add.append([T1,T2,T3])
df2 = pd.DataFrame(add, columns=colums)
mytable.add_rows(df2)
mytable doesn’t exist yet, so can’t be updated.
So how can I create the empty table before the button but display it after it, below the button ?
alican
January 29, 2021, 7:44pm
4
I think putting
mytable = st.table(df)
right before the if statement should fix the issue.
WBP2020
January 30, 2021, 10:27am
5
Hi Alican,
Yes it makes it working but in the layout I need the add button to be placed before the table ! That is the real problem
1 Like
Hi @WBP2020 ,
I once wrote a script that displays elements in expanders once
the user clicks on of the fixed buttons at the top. Check it out:
Hi Peeps,
kinda created a super smooth generic layout for putting buttons and functions into a widget.
[image]
Maybe some of you can use it.
import time
def app():
st.title("Generic Expander Widget")
def get_hungry():
### do sports
with st.spinner('Keep Running'):
while time.time() < (time.time() + 60 * 1800):
running()
st.success("Got Hungry")
def order_pizza():
### call pizza service
with st.spinner('While on Phone'):
calling()
st.success("Pizza ordered")
def wait():
with st.spi…
Is that helpful?
alican
January 30, 2021, 10:47am
7
btn = st.button('Add')
mytable = st.table(df)
if(btn):
add = []
T11 = int(T1.title())
T22 = int(T2.title())
T33 = int(T3.title())
add.append([T1,T2,T3])
df2 = pd.DataFrame(add, columns=colums)
mytable.add_rows(df2)
st.success("added")
1 Like
WBP2020
January 30, 2021, 10:58am
8
Oh yes ! this is it, how could I not think about it. thank you !
Thank you Chris also for you example, very interesting.
3 Likes