I want a button using dbc.Button and when it is clicked, it should start the animated race line chart. I have tried this but it’s not working. Any lead would be helpful.
x_axis = list(range(df.shape[0]))
y_axis = list(df['4. close'])
frames = []
for frame in range(1, len(x_axis)+1):
x_frame = np.arange(frame)
y_frame = list(df.iloc[:frame-1, 4])
curr_frame = go.Frame(data = [go.Scatter(x = x_frame, y = y_frame, mode = 'lines')])
frames.append(curr_frame)
dash_app.layout = html.Div(
children=[
html.H1(children="Stock Simulation"),
html.P(10000, id="acnt_bal", style={"text-align":"center"}),
dcc.Graph(id="example-graph", animate=True, style={'display':"None"}),
dbc.Button('Start', id='example-button2', color='primary',
style={'margin-bottom': '1em', 'margin-left': '46%'}),
html.P(id='para')
]
)
@dash_app.callback(
[Output('example-graph', 'style'),
Output('example-graph', 'figure')],
Input('example-button2', 'n_clicks')
)
def start_graph(n_clicks):
data = go.Scatter(x = np.array([1]), y = np.array([60.10]), mode='lines')
return {"display":'block'},dict(data = [data], layout = go.Layout(xaxis=dict(range=[0, df.shape[0]]),
yaxis=dict(range=[0, max(y_axis)])),
frames = frames,
frame = {'duration': 20, 'redraw':False},
transition = {'duration':0}),```