Closed gautamsabba closed 10 months ago
These don't work either. However, the label gets updated correctly.
return gr.update(label="New Symbols", choices=['A','B'])
return gr.Dropdown(label="New Symbols", choices=['A','B'])
Hi @gautamsabba there are two issues here:
Yes, in Gradio 4.x the .update()
method of components has been deprecated, now you can simply return the component itself
You'll want to make sure the output Dropdown component is interactive so that you can click on it and look through the options. By default, Gradio sets output components to be non-interactive, but you can change that by passing in interactive=True
This is a working version of your app:
import gradio as gr
categories = ['Long-Short Equity', 'Long Government', 'Multisector Bond', 'Emerging Markets Bond', 'Corporate Bond', 'Intermediate Government', 'Inflation-Protected Bond', 'Intermediate-Term Bond', 'Muni National Long', 'Unknown', 'High Yield Muni', 'Long-Term Bond', 'Muni California Long', 'Muni National Interm', 'Nontraditional Bond', 'World Bond', 'Short Government', 'Muni National Short', 'Short-Term Bond', 'Preferred Stock', 'Ultrashort Bond', 'High Yield Bond', 'Muni New York Long', 'Emerging-Markets Local-Currency Bond', 'Miscellaneous Region', 'Bank Loan', 'Commodities Broad Basket', 'Japan Stock', 'World Allocation', 'Tactical Allocation', 'Large Value', 'Foreign Large Growth', 'Energy Limited Partnership', 'Foreign Small/Mid Blend', 'Foreign Large Value', 'Foreign Large Blend', 'Europe Stock', 'Allocation--50% to 70% Equity', 'Financial', 'Diversified Emerging Mkts', 'Industrials', 'Mid-Cap Blend', 'Large Growth', 'Communications', 'Diversified Pacific/Asia', 'Foreign Small/Mid Value', 'Convertibles', 'Small Value', 'Latin America Stock', 'Equity Energy', 'Natural Resources', 'Real Estate', 'Large Blend', 'Small Blend', 'Consumer Cyclical']
def update_symbols(category):
symbols = ['FFIU', 'IGEB', 'VCIT', 'FCOR', 'SKOR', 'KORP', 'LQDI']
return gr.Dropdown(choices=symbols, interactive=True)
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("### Dropdown Tester")
with gr.Row():
category_dropdown = gr.Dropdown(choices=categories, label="Category")
symbol_dropdown = gr.Dropdown(label="Symbols", choices=[])
# Update the symbols dropdown when the category changes
category_dropdown.change(update_symbols, inputs=[category_dropdown], outputs=[symbol_dropdown])
demo.launch()
Thank you.
when i remove the options from the first drop down iam getting undefined for the options i selected in the dropdown_2 instead of giving me an empty drop_down
please tell me how to remove this bug @abidlabs
Describe the bug
Looks like update() on components is broken in 4.11.0
Have you searched existing issues? 🔎
Reproduction
System Info
Severity
Blocking usage of gradio