I want get back the index of current value from the animation slider every time the slider value changes. I try to set input callback to fig[‘layout’][‘sliders’][0][‘active’] but it does not work out. Is there any way to achieve this?
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.express as px
app = dash.Dash(__name__)
access_token = 'xxxxxxxxxx'
px.set_mapbox_access_token(access_token)
data_url = 'https://shahinrostami.com/datasets/time-series-19-covid-combined.csv'
data = pd.read_csv(data_url)
missing_states = pd.isnull(data['Province/State'])
data.loc[missing_states, 'Province/State'] = data.loc[missing_states, 'Country/Region']
data['Active'] = data['Confirmed'] - data['Recovered'] - data['Deaths']
data = data.dropna()
date_mask = data['Date'] == data['Date'].max()
fig = px.scatter_mapbox(
data, lat="Lat", lon="Long",
size="Active", size_max=50,
color="Deaths", color_continuous_scale=px.colors.sequential.Pinkyl,
hover_name="Province/State",
mapbox_style='dark', zoom=1,
animation_frame="Date", animation_group="Province/State",
height=600,
)
app.layout = html.Div([
dcc.Graph(id='my_graph', figure=fig),
html.Div(id='label'),
])
@app.callback(Output("label", "children"),
[Input("my_graph", "figure['layout']['sliders'][0]['active']")])
def get_index(value):
print(value)
return value
if __name__ == '__main__':
app.run_server(debug=True)