Hi,
I could not understand why the code below gives the error loading dependencies:
What I would like to achieve is:
-
Display b_radioitems based on a_radioitems (display b if and only if a = A or B), and,
-
Display ‘XX’ or ‘YY’ based on both a_radioitems and b_radioitems (display XX if and only if a = A and b = AA or display YY if and only if a = B and b = BB).
Do you have an idea how to make this code works correctly ?
Thank you very much for your help.
Marco
LIBRARIES
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
INITIALIZATION
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.config[‘suppress_callback_exceptions’]=True
LAYOUT
app.layout = html.Div([
html.H1(‘Callbacks Test’),
html.Div(
id='1',
children=[
dcc.RadioItems(
id='a',
options=[
{'label': 'A', 'value': 'A'},
{'label': 'B', 'value': 'B'},
{'label': 'C', 'value': 'C'}
],
value='A'
)
]
),
html.Div(id='2'),
html.Div(id='3')
])
@app.callback(Output(‘2’, ‘children’),
[Input(‘a’, ‘value’)])
def display_b_radioitems(a):
if a in [‘A’, ‘B’]:
return html.Div([
dcc.RadioItems(
id=‘b’,
options=[
{‘label’: ‘AA’, ‘value’: ‘AA’},
{‘label’: ‘BB’, ‘value’: ‘BB’}
],
value=‘AA’,
labelStyle={‘display’: ‘inline-block’}
)
])
@app.callback(Output(‘3’, ‘children’),
[Input(‘a’, ‘value’), Input(‘b’, ‘value’)])
def display_XXYY(a, b):
if a in [‘A’, ‘B’]:
if b == ‘AA’:
return ‘XX’
elif b == ‘BB’:
return ‘YY’
RUN APP
if name == ‘main’:
app.run_server(debug=True)