I have a problem with slow chart loading after changing tabs. I am using live graph and everything was smooth while it was taking input like this:
@app.callback(Output('tgraph', 'figure'),
[Input('twitt-symbols', 'value')],
events=[Event('t-graph-update', 'interval')])
The twitt-symbols
is id
of dcc.Input
but with this solution everytime I have switched the tabs, current input values were forgotten. So in the next solution I have used dcc.Store
outside of tabs to store data about last input and used those callbacks:
@app.callback(Output('twitterstorage', 'data'),
[Input('tweet-button', 'n_clicks')],
[State('twitt-symbols', 'value')])
def update_symbols(n_clicks, inputvalue):
data = inputvalue
print('symbol', data)
return data
@app.callback(Output('twitt-symbols', 'value'),
[Input('twitterstorage', 'data')])
def update_symbols(data):
return data
@app.callback(Output('tgraph', 'figure'),
[Input('twitterstorage', 'data')],
events=[Event('t-graph-update', 'interval')])
def update_tweet(symbol):
And everything works… but is slow. With first solution chart was already loaded right after changing tab but with the second solution I have to wait like 5-7sec before it loads. How to solve it? Is there any way to do it faster?
PS My tabs are different .py files and i render them by:
@app.callback(Output("tab_content", "children"), [Input("tabs", "value")])
def render_content(tab):
if tab == "analysis_tab":
return analysis.layout
elif tab == "settings_tab":
return settings.layout
else:
return settings.layout