I have plotted animated race line chart using graphing object in dash. When I click start button the race line chart starts. I want that if I click another button say “Show” then it should print the current data values of race line chart. How should I get the values?
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])
#y_frame = [y_frame]
curr_frame = go.Frame(data = [go.Scatter(x = x_frame, y = y_frame, mode = 'lines')])
frames.append(curr_frame)
title1 = "Stock Simulation of " + str(list(comp_name)[0])
figure = go.Figure(data=[go.Scatter(x = np.array([1]), y = np.array([60.10]), mode='lines')],
layout={'title':title1,
"updatemenus":[{"type":"buttons",
"pad":{'l':80, "t":200},
"x":0.4,
"y":0.6,
"xanchor":"left",
"yanchor":"top",
"showactive":True,
"buttons":[{
"label":"Start",
"method":"animate",
"args":[None, {"frame": {"duration":10,
"redraw":False},
"fromcurrent": True,
"transition": {"duration":0}
}
]
}],
}],
"xaxis":{"range":[0, df.shape[0]]},
"yaxis":{"range":[0, max(y_axis)]}
},
frames=frames
)
dash_app = dash.Dash(server=flask_app, name="Dashbar", url_base_pathname="/dash/")
dash_app.layout = html.Div(
children=[
html.H1(children="Welcome"),
#html.Div(children=""" """),
dcc.Graph(id="example-graph", figure=figure),
dbc.Button('Show', id='example-button', color='primary',
style={'margin-bottom': '1em', 'margin-left': '46%'}),
html.Div(id='para')
]
)
@dash_app.callback(
Output('para', 'children'),
Input('example-button', 'n_clicks')
)
def show_data(n_clicks):
if n_clicks is None:
raise PreventUpdate
else:
return "What to add here?"