Not getting Dropdown values in callback function

Hi,
I’m trying to get three dropdown values on a button click in callback python function. But I am getting only None values.

html.Div([
                    dcc.Dropdown(
                        options=[
                            {'label':'Bar Graph', 'value':'Bar Graph'},
                            {'label':'Line Graph', 'value':'Line Graph'}
                            ],
                        id='graph-type', 
                        placeholder='Graph Type'
                        ),
                    dcc.Dropdown(
                        options=col_dict_list,
                        id='x-axis', 
                        placeholder='X Axis Column'
                        ),
                    dcc.Dropdown(
                        options=col_dict_list,
                        id='y-axis', 
                        placeholder='Y Axis Column'
                        ),
                    html.Button(
                        'Generate Graph',
                        id='generate-btn',
                        style={
                            'borderRadius': '5px',
                            'textAlign': 'center',
                            'margin': '0 auto',
                            'alignItems': 'center'
                        },
                        n_clicks=0
                        ),
                ]),
@callback(Output('output-graph', 'children'),
              State('graph-type', 'graph_type'),
              State('x-axis', 'x'),
              State('y-axis', 'y'),
              Input('generate-btn','n_clicks'))
def generate_graph(graph_type,x,y,n_clicks):
    print('checking=',graph_type,x,y,n_clicks)
    if graph_type is not None and x is not None and y is not None and n_clicks != 0:
        if graph_type == 'bar':
            graph = ''
            print('checking bar graph')
        return graph

Screen Shot 2023-07-13 at 15.30.27

Any suggestion/resolution would be helpful, Thanks.

Hi @amrstech welcome to the forums.

The problem lies here:

@callback(Output('output-graph', 'children'),
              State('graph-type', 'graph_type'),
              State('x-axis', 'x'),
              State('y-axis', 'y'),
              Input('generate-btn','n_clicks'))

try:

@callback(Output('output-graph', 'children'),
              State('graph-type', 'value'),
              State('x-axis', 'value'),
              State('y-axis', 'value'),
              Input('generate-btn','n_clicks'))
1 Like

4 posts were split to a new topic: Help with dynamically created components