How to keep a button activate?

Hi everyone ! First thanks for the streamlit package that is very useful !

I just face a problem when I develop my streamlit application with the st.button.
I explain :

I get some “filters” that the user can apply as his choice. The first filter is the tab selecting (three tabs which provide differents data).
When the user chooses a tab, then he can choose some filters. But with the st.button, when the user choose another filter after the tab, the button is “restarted” and he goes back to the welcome page.

Is it possible to keep a button activate as long as another button is not selectionned ?

For illustrate it, look at this picture :

image

In red : the tab selection

In blue : the filters selection

When I click on a tab, I run to some visualisation but then when I click to a filter, the application restart because filter button is not keeping activate.

Thanks a lot for read me, I hope someone can help ! :slight_smile:

Axedl

@doll

Buttons set their value to True only in the instant they are clicked . After that, their value goes back to False.

In your use case you would be advised to use st.radio. Radio buttons lay out vertically, so that might not suit you. So, instead use st.checkbox in multiple columns. Then set and hold the value state of the checkboxes in st.session_state.

See “multi-page-app-with-session-state” for inspiration. If you want the page to reset, then use st.experimental_rerun to run the app from the top but still preserving the set states.

HTH,
Arvindra

Hi @asehmi !

Sorry for my latest reply…

I just come to you to say thanks to your answer. Like you say, I have to layout my buttons horizontally. With a little search in addition with you answer, I find a solution than can satisfy me !

So I use the radio button, but with a Widget style parameter. Just to inform you, if you apply this :

st.write('<style>div.Widget.row-widget.stRadio > div{flex-direction:row;}</style>', unsafe_allow_html=True)

You can make all your radio buttons horizontally. But it applies to ALL the radio buttons of the page.

For the moment I use this solution.

Thanks again,

Axel

1 Like

Hi @doll - nice that you found a solution, even though it’s bending the rules a little! (And you’re not the first to do so :upside_down_face:)

@doll - I’ve release a new sample app which may interest you!

Hi @asehmi !

Thanks a lot for your job that reflect as well what I need. It’s really detailed and it will be really useful to me !

Have a nice week, regards,

Axel

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.