How to disable button or any streamlit components

Hello team,

Do we have any way to disable & enable button or streamlit controllers? I have to disable a button after click & enable the same button after click of 2nd button.

1 Like

Hi @deepankar27 -

What user experience are you trying to develop here? Meaning, why does the button have to be disabled…does it cause a recalculation that you don’t want?

Hello @randyzwitch I want to force users to provide feedback on inference & then again repeat the step. Else users are skipping the feedback step.

Step1 :

Step 2:

import streamlit as st
import st_state_patch


def main():
	st.title("Data Categorization")
	txt = st.text_area("Paste your data here..")
	s = st.State() 
	if not s:
		s.pressed_first_button = False

	if st.button("Find Category")  or s.pressed_first_button:
		s.pressed_first_button = True # preserve the info that you hit a button between runs
		try:
			if txt != '':
				value = st.selectbox("Agree with result", ["Yes, I agree..", "Nah!! I don't"])
				if st.button("Submit report"):
					if value == "Yes, I agree..":
						st.write('Do this ...')
					elif value != "Nah!! I don't agree":
						st.write('Do that ...')
			else:
				st.write('No content found')
		except:
			st.write('Looks like I am having problem connecting my backend')
		

if __name__ == '__main__':
	main()

Hello @randyzwitch can you plz suggest anything on this?

I can’t promise anything @deepankar27, as this is a pretty specific question that I’d have to sit down and try myself. It feels like you could conditionally remove the button, but I’d have to think about it

1 Like