I’m creating a GPT-based application, wherein the user submits a form and some output is generated dynamically based on the submission; and I don’t want the user to be able to change their response after the LLM’s response has been outputted / is outputting.
And I am having trouble changing the state of the radio group in the form to disabled. I tried using session state, by explicitly changing the value of the session state variable in the code, but it doesn’t work.
This is my code:
# The function to change radio group state
def get_output(el_id):
st.session_state[f'rad_{el_id}_disabled'] = True
print(st.session_state[f'rad_{el_id}'])
# The main portion of the app where I'll get the user response from
def display_content(txt, opts, el_id):
container = st.container()
col1, col2 = container.columns([0.65, 0.35])
col1.write(txt[0])
col2.write(txt[1])
st.divider()
with col1:
with st.form(key=f'user_choice_{el_id}'):
st.session_state[f'rad_{el_id}_disabled'] = False
st.radio(txt[-1], opts, key=f'rad_{el_id}', disabled=st.session_state[f'rad_{el_id}_disabled'])
st.form_submit_button(label="Let's move on!", on_click=lambda: get_output(el_id))
I hoped that, in accordance with the st.radio docs, my radio group would get disabled as soon as I clicked the form submit button, but it does not get disabled. Instead, the user can very much change the radio selection.
Can someone please help me figure out to disable the radio group, please?