Combine dropdown and live update to graph

Hello,
I want to update a graph from dropdown and interval component. when i try as a callback multiple imputs the graph doesn’t work. here the code i wrote.
Please help!!!

<`@app.callback(
Output(“graph”, “figure”), [Input(“UC-memory-1”, “data”), Input(“data-update”, “n_intervals”)]
)
def update_graph(data):
df=pd.DataFrame.from_dict(data[‘Table1’])
df = UC1.get_riskhover_data(df)
[trace, layout] = UC1.create_callback_layout(df)
return {‘data’: trace, ‘layout’: layout,}>

Helo @taha! Welcome to Dash community! :slight_smile:

first tip: when you have a callback with multiple Inputs, the function should have the same number of variables.
I will comment your code… hope it helps a bit!

@app.callback(
         Output(“graph”, “figure”), 
         [Input(“UC-memory-1”, “data”), #is this one the dropdown? If it is, the parameter should be "value" instead of "data".
          Input(“data-update”, “n_intervals”)]) #what kind of element is this?
def update_graph(variable1, variable2): #the value of the variables will be assign in the same order of the inputs.
   df=pd.DataFrame.from_dict(data[‘Table1’])
   df = UC1.get_riskhover_data(df)
   [trace, layout] = UC1.create_callback_layout(df)
    #I don't really find how you're using your variable to change the data and layout.
   return {‘data’: trace, ‘layout’: layout}

I think you should go over DASH documentation and look for some examples!
It will help you a lot!

https://dash-gallery.plotly.host/Portal/

Thks Cecilia for your reply,
i made the modification but it doesn’t work :frowning_face:

#store-1 Callback
@app.callback(
Output(“UC-memory-1”, “data”), [Input(“my-dropdown”, “value”)]
)
def update_memory(value):
total_time = cf.get_current_time()
datatest=GU.get_all_data2(total_time, value)
return datatest

#UC1 Callback
@app.callback(
Output(“graph”, “figure”), [Input(“UC-memory-1”, “data”), Input(“data-update”, “n_intervals”)]
)
def update_graph(data, n_intervals):
df=pd.DataFrame.from_dict(data[‘Table1’])
df = UC1.get_riskhover_data(df)
[trace, layout] = UC1.create_callback_layout(df)
return {‘data’: trace, ‘layout’: layout,}>

With only this part of the code I really can’t help you … I can’t understand what you’re trying to do.

one other tip, when posting for help, use (4 of this ` in a sequence with no space before your code) and your code will keep code appearance!

It works, Thk you soo much Cecilia for your quick answer.

1 Like