Updating annotations in animation (per frame)


I'm stuck again :wink: while trying to animate two violin plots for comparison (over time) with plotly.
For each frame (timestamp), I want to plot specific values (mean, median, total number of samples at this point) somewhere on the plot (in the legend, on top, corner right ...).

I thought annotations would be the right way to implement this - but I haven't been able to show dynamic values (or a pre-defined list, related to the current frame) so far. Until now, I just can show a static text!

Has anyone an idea? Best regards!


df_test <- data.frame(side=rep(c("left","right"), 100), 
                       daysPassed=c(sample(1:100, 200, replace=T)), month=c(rep(201601,20),rep(201602,20),rep(201603,20),rep(201604,20),rep(201605,20),rep(201606,20),rep(201607,20),rep(201608,20),rep(201609,20),rep(201610,20))

df_test %>%
    x = ~side,
    y = ~daysPassed,
    frame = ~month,
    split = ~side,
    type = 'violin',
    points = F,
    spanmode = "hard",
    showlegend = F,
    box = list(
      visible = F
    meanline = list(
      visible = T
  ) %>% 
    annotations = list(text = ~month, showarrow = F),
    yaxis = list(range = c(0, max(df_test$daysPassed, na.rm=T)),
                 title = "Days Passed",
                 zeroline = T,
                 autorange = F),
    xaxis = list(
      title = "",
      showticklabels = TRUE