Added start/stop button for autoplay

This commit is contained in:
George 2024-06-30 14:44:23 -07:00
parent 72ec91c8ed
commit e991e8e876

View File

@ -845,6 +845,7 @@ if __name__ == "__main__":
# App layout # App layout
app.layout = [ app.layout = [
html.Button('Refresh Data', id='button', n_clicks=0), html.Button('Refresh Data', id='button', n_clicks=0),
html.Button('Auto Play', id="start-button", n_clicks=0, disabled=True),
# html.Div(children='Pick A Symbol from Dropdown List: '), # html.Div(children='Pick A Symbol from Dropdown List: '),
# html.Hr(), # html.Hr(),
# dcc.RadioItems(options=['pop', 'lifeExp', 'gdpPercap'], value='lifeExp', id='controls-and-radio-item'), # dcc.RadioItems(options=['pop', 'lifeExp', 'gdpPercap'], value='lifeExp', id='controls-and-radio-item'),
@ -860,12 +861,28 @@ if __name__ == "__main__":
dcc.Interval( dcc.Interval(
id='interval-component', id='interval-component',
interval=3*1000, # in milliseconds interval=3*1000, # in milliseconds
n_intervals=0 n_intervals=0,
) disabled=True,
),
] ]
# start button callback
@callback(Output('interval-component', 'disabled'),
Output("start-button", "children"),
Input("start-button", "n_clicks"))
def start_cycle(n):
if n:
if n%2 == 0:
return True, "Auto Play"
else:
return False, "Pause"
return no_update
# interval callback
@callback(Output('controls-and-radio-item', 'value'), Input("interval-component", "n_intervals")) @callback(Output('controls-and-radio-item', 'value'), Input("interval-component", "n_intervals"))
def cycle_syms(n): def cycle_syms(n):
# if not n:
# return no_update
syms=["AMZN", "GOOGL", "AAPL", "SPY"] syms=["AMZN", "GOOGL", "AAPL", "SPY"]
return syms[n % 4] return syms[n % 4]
@ -874,8 +891,8 @@ if __name__ == "__main__":
j_obj = intelligent_loop_plots() j_obj = intelligent_loop_plots()
return j_obj return j_obj
# button callback # retrieve data button callbacks
@app.callback( @callback(
Output("button", "disabled", allow_duplicate=True), Output("button", "disabled", allow_duplicate=True),
Input("button", "n_clicks"), Input("button", "n_clicks"),
prevent_initial_call=True, prevent_initial_call=True,
@ -916,6 +933,7 @@ if __name__ == "__main__":
@callback( @callback(
Output(component_id='controls-and-radio-item', component_property='options'), Output(component_id='controls-and-radio-item', component_property='options'),
Output(component_id='button', component_property='disabled'), Output(component_id='button', component_property='disabled'),
Output(component_id='start-button', component_property='disabled'),
Input(component_id='signal', component_property='data'), Input(component_id='signal', component_property='data'),
) )
def update_dropdown(in_data): def update_dropdown(in_data):
@ -930,7 +948,7 @@ if __name__ == "__main__":
print("dropdown menu options updated") print("dropdown menu options updated")
# all_plot_sym = ["SPY", "AMZN"] # all_plot_sym = ["SPY", "AMZN"]
return sorted(all_plot_sym), False return sorted(all_plot_sym), False, False
@callback( @callback(
Output(component_id='controls-and-graph', component_property='figure'), Output(component_id='controls-and-graph', component_property='figure'),