Hide sidebar with line of code

Hi, would it be possible to hide the sidebar after clicking in a button. My app has a list of questions on the sidebar and button at the end. When the user returns to the top of the sidebar, to close it. The app is updated and all the answers are lost. I’d like to hide the sidebar when the button is pressed.


if st.sidebar.button('Analyze profile'):
    st.sidebar(visibility=False)  # something like this