Hi all,
I ran into this today, and either need more coffee or something is not working properly. When I attempt to update the values of one dropdown from another, the options populate in the second dropdown, but the value does not.
I’ve attached some code and a gif.
Any help is much appreciated.
Thanks.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input
from dash.dependencies import Output
import db.api as db
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.config['suppress_callback_exceptions'] = True
app.layout = html.Div(children=[
dcc.Location(id='url', refresh=False),
html.H1(children='Demo'),
html.Div(
children=[
html.Label("Sex"),
dcc.Dropdown(
id="dropdown-sex",
options=[
dict(label="Both", value="both"),
dict(label="Male", value="male"),
dict(label="Female", value="female")
],
value="both"
),
html.Label("Phenotype code"),
dcc.Dropdown(id="dropdown-pheno"),
html.Div(id="selected-pheno-div")
]
),
])
@app.callback(Output("dropdown-pheno", "options"),
[Input("dropdown-sex", "value")])
def update_pheno_dropdown(sex):
vals = db.get_gwas_for_sex(sex).values
return [dict(label=elem, value=elem) for elem in vals]
@app.callback(Output("dropdown-pheno", "value"),
[Input("dropdown-pheno", "options")])
def set_pheno_value(options):
val = options[0]["value"]
print(f"setting value to {val}")
return val
@app.callback(Output("selected-pheno-div", "children"),
[Input("dropdown-pheno", "value")])
def show_selected_pheno(pheno):
return pheno
if __name__ == '__main__':
app.run_server(debug=True)
dash==0.35.1
dash-core-components==0.42.1
dash-html-components==0.13.4
dash-renderer==0.16.1
dash-table==3.1.11