Plotly animation / colors change by group

Hi Forum,
firstly, huge congrats to the plotly devs for providing such a neat library with high level API that simply looks stunning from the get go. I love how easy it is to create animations… alas, i’m struggling a lot with what is provided in the documentation on making animations:

I’m interested in creating a bar chart showing two categories, so far so easy:

my data

period value rank mygroup
1 100 2 blue
1 500 1 red
1 200 2 blue
2 100 2 blue
2 500 1 red
2 200 2 blue

import plotly.express as px
fig = px.bar(df, y=“rank”, x=“value”, color=‘mygroup’,
animation_frame=“period”)

which looks fine – however if i wanted to change the coloring dynamically
period value rank mygroup
1 100 2 blue
1 500 1 red
1 200 2 blue
2 100 2 blue
2 500 1 blue
2 200 2 blue

what plotly ends up doing is to show the graph with a blank bar where the red bar should show up.

I’m really not sure what role animation_group plays and i can’t figure out how to do the dynamic change of colors using the API, so any help would be greatly appreciated!

Thanks!