Sharing Data between Callbacks with Hidden Div

Hey Dash Community,

I’m wondering if it’s possible to share Data with a hidden Div and use this one in another callback additionally to other Input Values. I’ve just seen examples where the Input value was just the hidden Div Input and no more other Inputs.
Here’s an example:

@app.callback(Output('intermediate-value', 'children'), [Input('dropdown', 'value'), Input('filter2', 'value'), Input('filter3', 'value')])
def getFilterData:
      ...
      return json.dumps(data)

@app.callback(Output('dataTableContainer', 'children'), [Input('intermediate-value', 'children')])
def generateDataTable: 
    ....
    return dataTable


@app.callback(Output('DetailsTableContainer', 'children'), [Input('intermediate-value', 'children'),
Input('datatable', "derived_virtual_data"),
     Input('datatable', "derived_virtual_selected_rows")])
def generateDetailsTable:
    ....
    return DetailsTable

Every answer is appreciated.
Thank you and merry christmas.

Yes, this is perfectly possible.

That being said, I would use the dash store component instead. It solves the issue of storing data, which was previously addressed by the hidden-div-hack,

https://dash.plot.ly/dash-core-components/store

Merry Christmas :slight_smile:

3 Likes

Thank you so much, I will try that!

The second example on the referenced page, “Share data between callbacks” appears to have unneeded, unexecuted code:

if data is None:
    raise PreventUpdate

Why not have cleaner code?

Thanks @Emil, the direction has been helpful!