# How to dynamically update the widget?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-dynamically-update-the-widget%2F57878%3E%5C
**Category:** 🔒 Gradio\
**Created:** [October 9, 2023, 8:49am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-dynamically-update-the-widget%2F57878 "2023-10-09T08:49:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivance](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/shivance/32/18366_2.png) [@shivance](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fshivance)%5C
**Post date:** [October 9, 2023, 8:49am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-dynamically-update-the-widget%2F57878%2F1 "2023-10-09T08:49:06Z")

</div>

I’m new to gradio and working on a project.

My requirement is as following.

1. I have a dropdown. It has option A, B and C
2. Just below this dropdown I have created an accordion `Advanced Controls` and it has some controls.  
Based on selected value of option from dropdown these controls will change. But how do I achieve this?

I’m trying to do something like this:

```auto
 model_dropdown = gr.Dropdown(
                    choices=list(...),
                    label="Label",
                    show_label=True,
                    interactive=True,
                )

# advanced_control_inputs = None

with gr.Accordion(
    label="Advanced Controls", open=False, visible=True
) as advanced_control_accordion:
    with gr.Row():
        advanced_control_inputs = stable_diffusion_input_ui()

def update_dropdown(dropdown_value):
    if dropdown_value is not None:
        # Update the advanced controls based on the selected value
        if dropdown_value == "Option_A":
            advanced_control_inputs = UI_option_A()
        else:
            advanced_control_inputs = UI_option_B()

        # advanced_control_accordion.update(advanced_control_inputs)

        gr.Info(f"Updated the Advanced Controls UI!")                                

        return [
            gr.Dropdown.update(
                choices=list(
                    ...
                ),
                label="Label",
                show_label=True,
                interactive=True,
            ),
            *advanced_control_inputs
        ]

dropdown.change(
    fn=update_dropdown,
    inputs=dropdown,
    outputs=[dropdown, *advanced_control_inputs],
)

```

UI\_option\_A look something like:

```auto
def ui_option_A():
    text = gr.Textbox(label="Negative Prompt", show_label=True)

    with gr.Column():
        height = gr.Slider(
            minimum=64,
            maximum=1024,
            step=1,
            value=512,
            label="Height",
            show_label=True,
        )
    with gr.Column():
        width = gr.Slider(
            minimum=64,
            maximum=1024,
            step=1,
            value=512,
            label="Width",
            show_label=True,
        )
    return [text, height, width]

```

---

<div class="post-metadata">

**Author:** ![murphybridget](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@murphybridget](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmurphybridget)%5C
**Post date:** [October 25, 2023, 7:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-dynamically-update-the-widget%2F57878%2F2 "2023-10-25T07:17:15Z")

</div>

Thank you for sharing.

---

<div class="post-metadata">

**Author:** ![murphybridget](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@murphybridget](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmurphybridget)%5C
**Post date:** [November 1, 2023, 8:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-dynamically-update-the-widget%2F57878%2F3 "2023-11-01T08:40:06Z")

</div>

Did you finally made it work?
