I’m going to try my best to explain this giant problem i’ve been working on for days. I hit an api for live updates for crypto data, and I want my graph to update each time a new pull comes in from the api (30 seconds). Here’s what I have so far, then i’ll go about explaining my issues.
`app = dash.Dash(__name__)
app.layout = html.Div(
html.Div(className='container-fluid', children=
[
html.Div(className='row',
children=html.Div(dcc.Graph(id='live-graph', animate=True), className='col s12 m12 l12')),
dcc.Interval(
id='graph-update',
interval=30000
)
]),
)
@app.callback(
Output('live-graph', 'figure'),
events=[Event('graph-update', 'interval')]
)
def graph_update():
data = {
'data': [{'close': stock_df.Close,
'decreasing': {'line': {'color': '#808080'}},
'high': stock_df.High,
'increasing': {'line': {'color': '#17BECF'}},
'low': stock_df.Low,
'name': 'Trace 1',
'open': stock_df.Open,
'showlegend': True,
'type': 'candlestick',
'uid': '59f45c30-fa3a-459e-bc6d-f4643f4ed55e',
'x': stock_df.Date,
'yaxis': 'y2'}],
'layout': {'legend': {'bgcolor': '#F5F6F9', 'font': {'color': '#4D5663'}},
'margin': {'b': 30, 'l': 30, 'r': 30, 't': 30},
'paper_bgcolor': '#F5F6F9',
'plot_bgcolor': '#F5F6F9',
'showlegend': True,
'titlefont': {'color': '#4D5663'},
'xaxis': {'anchor': 'y2',
'gridcolor': '#E1E5ED',
'rangeselector': {'bgcolor': 'rgba(150, 200, 250, 1)',
'buttons': [{'count': 1,
'label': '1m',
'step': 'month',
'stepmode': 'backward'},
{'count': 1,
'label': '1y',
'step': 'year',
'stepmode': 'backward'}],
'font': {'size': 13},
'visible': False,
'x': 0,
'y': 0.9},
'rangeslider': {'visible': False},
'showgrid': True,
'tickfont': {'color': '#4D5663'},
'title': '',
'titlefont': {'color': '#4D5663'},
'zerolinecolor': '#E1E5ED'},
'yaxis': {'gridcolor': '#E1E5ED',
'showgrid': True,
'showticklabels': False,
'tickfont': {'color': '#4D5663'},
'title': '',
'titlefont': {'color': '#4D5663'},
'zerolinecolor': '#E1E5ED'}}
}
return {data}
server = app.server
dev_server = app.run_server(debug=True)
`
This is embedded in a function “tick”, which ticks when it hits the api. I’ve had a range of problems when trying to fix this, but currently it will set up the graph, plot 1 candlestick chart in the df, then won’t run the rest of the python code and allow for another “tick”. I’ve done a lot of research on this, and since it is within a function that is being called every 30 seconds, I don’t think i’ve found anything that will work. Thank you in advance!