How to send data from call back to the graph

0

Hi I am new to Dash Plotly, Based on the dropdown I am loading graphs. So i have a callback function which returns data. How do I go about sending that data to the graph?

Dropdown:

    dcc.Dropdown(
        id='dropdown',
        options=[
            {'label':'Production', 'value':'prod'},
            {'label':'Attrition', 'value':'attri'}

        ],
        multi=True,
        value="MTL",



    )

Call Back
@app.callback(Output(‘output’, ‘children’),
[Input(‘dropdown’, ‘value’)])
def update_output_1(value):
if value == ‘prod’:
cur.execute(
"select distinct extract(year from last_hire_date) as yr, "
“count(*) from associate_info group by yr order by yr ASC”)
trend = cur.fetchall()
x_trnd, y_trnd = zip(*trend)
x_trnd = list(x_trnd)
y_trnd = list(y_trnd)
x_t = [int(i) for i in x_trnd]
y_t = [int(y) for y in y_trnd]
return x_t, y_t
elif value== ‘attri’:
return len(value)
else:
return value

what do you want to send to the graph… a figure or what… :thinking:

Take a look at the examples in this page of the User Guide. You’ll need to make the output of your callback a) a graph object itself or b) a component of the graph object you pre-built in your layout. In your example, if you want the output of your callback to be the children element of a Div called ‘output’, you’ll need to return an entire dcc.Graph object instead of just the value you calculate based on your dropdown.

https://dash.plot.ly/getting-started-part-2