I am writing simple app with Dash and I have problem with making the live graph. I have made two tabs and want to display the live graph on one of them. I made an index.py
file with basic layout:
app.layout = html.Div(
[
#header
html.Div([
html.Span("Automation for Binance", className='app-title'),
],
className='row header',
),
html.Div([
dcc.Tabs(
id="tabs",
style={"height":"20","verticalAlign":"middle"},
children=[
dcc.Tab(label="Analysis", value="analysis_tab"),
dcc.Tab(label="Settings", value="settings_tab"),
],
value="analysis_tab",
)
],
className="row tabs_div"
),
html.Div(id="tab_content", className="row", style={"margin": "2% 3%"}),
])
@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 html.Div([
html.H3('Tab content 1')
])
else:
return analysis.layout
if __name__ == "__main__":
app.run_server(debug=True)
In the same directory as index.py
I made apps folder with __init__.py
and 2 files for each tab as external apps, here is my file for first tab analysis.py
:
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
def candlestick_chart(df):
trace = go.Candlestick(x=df.Date,
open=df.Open,
high=df.High,
low=df.Low,
close=df.Close)
layout = go.layout(
xaxis=dict(range=[df.Date[-30], df.Date[-1]]),
plot_bgcolor=colors['background'],
paper_bgcolor=colors['background'],
font=dict(color=colors['text']),
)
return {'data':[trace], 'layout': layout,}
layout = [
html.Div([
html.Div(
dcc.Graph(
id="price-graph",
style={"height": "90%", "width": "98%"},
),
dcc.Interval(
id="graph-update",
interval=4000,
)
)
])
]
@app.callback(Output('price-graph', 'figure'),
events=[Event('graph-update', 'interval')])
def update_graph(df):
df = manager.get_candles('BTCUSDT', '1m')
return candlestick_chart(df)
Now my problem is that when I run my app all what I get is empty candlestick chart with no data. And in the console I don’t even see auto updating POST responses. When I was trying to make “test chart” without tabs just one file and callback everything worked perfectly now it doesn’t even try to update or download data.
What Am I doing wrong?