Freezing/disabling multiselect after clicking button

Hello, I’ve just started and am really enjoying learning your platform. I was wondering if there is a button to disable or freeze a widget using a click button.
here’s a snippet of my code that I want to implement.

    # 2. Select Models to Run
    if st.session_state.upload_file:
        st.header('Select model')
        model_options = st.multiselect(
            "Choose Models to run",
            options = ['Logistic Regression', 'Random Forest'],
            default = ['Logistic Regression', 'Random Forest'],
            key = 'multiselect_model'
        )

        finalize_button = st.button('Finalize Model')

        if finalize_button:
            # I want to freeze the multiselect widget, or disable the user from changing the setting
            st.write('You have selected ', model_options)

Hi @Jaeho_Kim ,

Here’s one of the workaround which rn came to my mind. I’m unsure if this is the best way to handle this workflow, possibly there are options to access to the disabled arguments as well.

import streamlit as st

# Perhaps not necessary to store the value
if 'disable_opt' not in st.session_state:
    st.session_state.disable_opt = False

emp = st.empty()
multi = emp.multiselect("Choice", options=['This', 'That'],disabled = st.session_state.disable_opt)


if st.button("Hide"):
    st.session_state.disable_opt = True
    st.write('You have selected ', multi)
    multi = emp.multiselect("Choice", options=['This', 'That'],disabled = st.session_state.disable_opt)
    st.snow()

streamlit-test3-2022-03-09-10-03-77

2 Likes

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