How to programmatically enable or disable components?
Hi,I am new to Gradio and I am struggling to figure out how to enable or disable (i.e. change the interactive flag) of component B based on events in component A.My question can be best illustrated in code:import gradio as gr                                                             

def b_clicked(o):
    # how to enable the other button "o"?
    pass

with gr.Blocks() as app:
    b = gr.Button("Enable the other obutton", interactive = True)
    o = gr.Button("Other Button", interactive = False)
    b.click(fn = b_clicked, inputs = o)

if __name__ == "__main__":
    app.launch()I know there is agr.update()method, which in theory should allow to update the value of theinteractivesetting, but I failed to understand how to reference another component. Indef b_clicked(o)theoparameter is a string and not an object.I tried wrapping the whole code into a class, thus gaining access to the actual button objects viaself.bandself.oand then trying something like:def b_clicked(self):
    self.o.update(interactive = True)However nothing changed on the screen. I also tried to add anapp.render()after theupdate, but this did not help either.What is the proper way to accomplish that?Kind regards,Jin
2023-09-15T10:15:56Z
Enjoy, I hope it’s not too lateimport gradio as gr                                                             

def b_clicked(o):
    return gr.Button.update(interactive=True)
    

with gr.Blocks() as app:
    b = gr.Button("Enable the other obutton", interactive = True)
    o = gr.Button("Other Button", interactive = False)
    b.click(fn = b_clicked, inputs = b, outputs = o)

if __name__ == "__main__":
    app.launch()
2023-09-16T13:05:38Z
Hi@Bigiman,thank you, this works as expected! It’s never too lateEven if I did not use Gradio for my project in the end and switched to Glade + GTK (not due to this issue, but due to how Gradio handles long videos), I still appreciate the answer, so that I know how to do it properly in the future.I guess I failed to understand the whole concept behind it, my assumption was that the handler gets instances of other components as parameters, allowing me to access them. In your example however, theoparameter is not being used in the handler at all?How does the code:def b_clicked(o):
    return gr.Button.update(interactive=True)know,whichbutton it is updating? Is this implied byoutputs = o?How would this work if I wanted to update several components at once, say, if we had “Other Button 1” and “Other button 2” there?Kind regards,Jin
2023-09-17T14:44:48Z
Hi Jin,You can define both output and inpus as lists.E.g. you define output as the list of 2 parameters ([o,oo]. In the return of the function (b_clicked) you send back 2 arguments, the 1st argument correspondents to the 1st element of the output list (o), the 2nd argument correspondents to the 2nd element of the output list (oo)import gradio as gr                                                             

def b_clicked(b):
    return gr.Button.update(interactive=True), gr.Button.update(interactive=True)
    

with gr.Blocks() as app:
    b = gr.Button("Enable the other obutton", interactive = True)
    o = gr.Button("Other Button1", interactive = False)
    oo = gr.Button("Other Button2", interactive = False)
    b.click(fn = b_clicked, inputs = b, outputs = [o,oo])

if __name__ == "__main__":
    app.launch()
2023-09-17T19:00:20Z
Aaah, now I get it, thank you for the explanation,@Bigiman! That was the missing link for me, theoutputslist which is the callback function parameter corresponds to the return values of the callback function, now it’s clear.