Callback with figure as one of the inputs and the output

I am using a set of drop down menus to filter a database and create a dynamic a experimental table. The table is dynamic so it gets remade with different entries when the database is searched with different drop down menu options.

When an item in the table is selected I am trying to add it to the plotly figure and when it is deselected I am trying to remove it from the figure.

I think one way to do this would be to pass the figure as an input and output to a function as a callback. Unfortunately adding my-graph figure as an input causes an error ā€œError loading dependenciesā€.

This is the piece of code causing me trouble, is there anyway to access the figure data without passing it into the callback function?

@app.callback(Output('my-graph', 'figure'), 
             [Input('dymanic_datatable', 'rows'),
              Input('dymanic_datatable', 'selected_row_indices'),
              Input('my-graph', 'figure') #this line causes the error
              ])
def update_graph_data(rows, selected_row_indices,figure):
             figure out if the datatable has been updated in a way that the graph needs updating.....

Hi, IĀ“m doing something similar, I used sharing data between callbacks.

see Multiple callbacks sharing a variable

Hope it helps