I’m in the same situation as this post.
I’m trying to implement the option 1 proposed by chriddyp. But I can’t figure out how to do “set the data on page load and pass it through to different callbacks with hidden divs”.
Here is what I have implemented but I’m not sure where I’m going.
I did turn my app.layout
into a function and I’d like to know how to set the data on page load. I understand that I should do it in a hidden div but I don’t get what could by the Input
.
def serve_layout():
return html.Div(children=[
dcc.Graph(id='graph1'),
dcc.Interval(
id='refresh-data',
interval=1000
),
html.Div(id='intermediate-data', style={'display': 'none'})
])
app.layout = serve_layout
@app.callback(
Output('intermediate-data', 'children'),
[Input(....)]
)
def load_data(....):
data = MyDB.query.filter_by(...)
data_values = pd.DataFrame([(d.col1, d.col2) for d in data], columns=['col1', 'col2'])
return data_values
Can you help me? Thanks