Can`t handle correctly with buttons

Hi guys,

I’m having some issues with buttons. Spent a few hours today trying to make it work correctly but i’m still having problems.
My app works quite ok, it show a sentence with 2 buttons (like/dislike), user click on it, things are saved to the database. But after that, I need the page to be reloaded or reload the next question.

Using SessionState, I can get all usefull info and it works great too. If the user click the Home Button or reload the page, things works ok.

Do streamlit have a rerun or GoToSomeLineOnTop method?

Below you have 2 very simple situations where I don`t know how to solve.

** FIRST EXAMPLE - I have to click twice Stop Playing to have the buttons gone. **

#reload_from_here()
population = ['cars','traveling','pizza']
if state.show_message == True:
    item = random.sample(population, 1)
    st.text(item)
    if st.button('like'):
        pass
    if st.button('dislike'):
        pass
    if st.button('Stop playing'):
        state.show_message = False

** SECOND EXAMPLE - a simpler example, I just want to get rid of the button after user click. Same thing, need to click twice to get the desired behavior.**

if state.show_message:
    if st.button('skip'):
        state.show_message = False

I have lots of things happening before those buttons. they are not being updated aswell.

What am I missing out? Thx

Updating in case someone else faces the same issue.

HIDE A BUTTON AFTER CLICK:

my_placeholder = st.empty()
if my_placeholder.button("Hide me!"):
    my_placeholder.empty()

USING THIS SAME APPROACH:

placeholder_skip = st.empty()
if state.show_message:
    if placeholder_skip.button('skip'):
        state.show_message = False
        placeholder_skip.empty()

The first example above becomes a bit more complicated with multiple placeholders. But at least for me, it was enough for now. Things working here. Thx

1 Like