gradio
gradio copied to clipboard
gr.update Failed to update gr.State
Describe the bug
It seems that the gr.State value cannot be updated through gr.update. Is there something wrong with my operation?
Have you searched existing issues? 🔎
- [X] I have searched and found no existing issues
Reproduction
import gradio as gr
def click_btn1():
return gr.update(value="already clicked btn1"), gr.update(value=True)
def click_btn2(click_flag):
ret = "click_flag=False"
if click_flag:
ret = "already clicked btn1 and btn2"
return gr.update(value="already clicked btn2"), gr.update(value=ret)
with gr.Blocks() as demo:
click_flag = gr.State(False)
btn1 = gr.Button(value="btn1")
btn2 = gr.Button(value="btn2")
display_area = gr.Textbox("")
btn1.click(fn=click_btn1, inputs=None, outputs=[btn1, click_flag])
btn2.click(fn=click_btn2, inputs=[click_flag], outputs=[btn2, display_area])
demo.launch(server_name="0.0.0.0", server_port=7860, inbrowser=True)
Screenshot
Logs
No response
System Info
No errors were reported
Severity
Blocking usage of gradio
Indeed that is a bug, thanks for reporting @coolboyqu. For now, the workaround (which presumably you know) would be to just return True
instead of gr.update(True)
for the gr.State
component