Hi everyone,
I have dashboard with various graphs in a chained callback. One of them is a choropleth map with a slider for the years of my time-series data (1975-2014). Now I want to access the current year of the slider to update the graphs in the chained callback as the slider moves. I suppose there is not way to access the animation_frame of a simple plotly express choropleth (although that would be the easiest solution), so I created a plotly graph_object :
fig = go.Figure(data=[trace_base], layout=layout, frames=frames)
The whole thing is wrapped in a function that I call in the callback function. Is there a way to return the current year as part of the function or any other way to access the current year?
Actually the choropleth even displays the current year as part of the slider arguments but all I can access is the first year not the changing year as it loops through years.
sliders=[{
'active': 0,
'yanchor': 'top',
'xanchor': 'left',
'currentvalue': {
'font': {'size': 20},
'prefix': 'Year:',
'visible': True,
'xanchor': 'right'
},
'transition': {'duration': 300, 'easing': 'cubic-in-out'},
'pad': {'b': 10, 't': 50},
'len': 0.9,
'x': 0.1,
'y': 0,
'steps': [{'method': 'animate', 'label': str(year), 'args': [[str(year)], {'frame': {'duration': 300, 'redraw': True}, 'mode': 'immediate'}]} for year in years]
}]
Or is it better practice to have the slider as a separate dash component rather than using the slider of the choropleth?
I’m new to this so any help with this would be much appreciated!