Plotly.R: Multiple tracers in for loop using list of data.frames don't display correctly

Hi,

I have a list of data.frames, each data.frame has data for one singular date. I hope to use plotly to be able to show the first barplot for day 1, and scrolling through dates with a slider, for each day i want to see the particular barplot. Each barplot also has some other static plots - in the sense that the static part does not change from one day to the next, but the data for barplots do. Everything is done within R. (imagine the static part as a kind of logo if you wish).

A toy sample code is here, but the final result is not what i am looking after. Evidently i am missing an important part, but i am not sure where.

####################################

a test

library(plotly)

t1 <- data.frame(st=c(β€œa”, β€œb”, β€œc”, 0, 0, 0, β€œd”, β€œe”, β€œf”),
x1 =c(13,2,4,0,0,0,19,21,7),
x2 = c(13,2,4,0,0,0,19,21,7)+10, date1 = as.Date(rep(β€œ1/12/20”, 9),"%m/%d/%y"))

t2 <- data.frame(st=c(β€œa”, β€œb”, β€œc”, 0, 0, 0, β€œd”, β€œe”, β€œf”),
x1 =c(15,2,7,0,0,0,20,25,10),
x2=c(15,2,7,0,0,0,20,25,10)+10, date1 = as.Date(rep(β€œ3/5/20”, 9),"%m/%d/%y"))

t3 <- data.frame(st=c(β€œa”, β€œb”, β€œc”, 0, 0, 0, β€œd”, β€œe”, β€œf”),
x1 =c(20,5,10,0,0,0,23,33,14),
x2=c(20,5,10,0,0,0,23,33,14)+10,date1 = as.Date(rep(β€œ6/25/20”, 9),"%m/%d/%y"))

t4 <- data.frame(st=c(β€œa”, β€œb”, β€œc”, 0, 0, 0, β€œd”, β€œe”, β€œf”),
x1 =c(27,11,12,0,0,0,31,35,22),
x2=c(27,11,12,0,0,0,31,35,22)+10, date1 = as.Date(rep(β€œ8/17/20”, 9),"%m/%d/%y"))

t5 <- data.frame(st=c(β€œa”, β€œb”, β€œc”, 0, 0, 0, β€œd”, β€œe”, β€œf”),
x1 =c(28,23,17,0,0,0,39,37,28),
x2=c(28,23,17,0,0,0,39,37,28)+10, date1 = as.Date(rep(β€œ9/11/20”, 9),"%m/%d/%y"))

tt <- list(t1, t2, t3, t4, t5)
n2 <- length(tt)

fig <- plot_ly()
steps<- list()

for (i in 1:n2){

step <- list(args = list(β€˜visible’, rep(FALSE, length(tr4))),
method = β€˜restyle’, label="")
step$args[[2]][i] = TRUE
steps[[i]] = step
steps[[i]]$label <- paste(β€œDate:”,tt[[i]][1,4])

fig<-add_trace(fig, x=tt[[i]][,3], type = 'bar', orientation = 'h',
		showlegend=FALSE, marker=list(color="red"),
		text=paste(tt[[i]][,1], "vals=", tt[[i]][,2]), hoverinfo = "text")%>% 
add_polygons(x=c(0,5, 5,0), y=c(6,6, 9, 9),
	fillcolor="blue", line = list(color = "blue"), 
	inherit = FALSE, hoverinfo ="skip")%>%
add_trace(x=rep(c(1, 3,2, 4),2), y=rep(seq(6,9), each=2), 
	type="scatter", mode="markers",
	marker = list(size = 14, color = rainbow(8), symbol = 1), 
	inherit = FALSE, hoverinfo ="skip")%>%
layout(
xaxis = list(
   zeroline = FALSE,

showline = FALSE,
showticklabels = FALSE,
showgrid = FALSE
),
yaxis = list(
showline = FALSE,
showticklabels = FALSE,
showgrid = FALSE
),
bargap = 0,
hoverlabel=list(bgcolor=β€œwhite”),
showlegend = FALSE,
title=list(text=paste(β€œtest”),
font=list(size=20), y=0.96)
)
}

fig <- fig %>%
layout(sliders = list(list(active = 0,
currentvalue = list(prefix = β€œβ€),
steps = steps)))

fig
###########################

For first day every data in all 5 data.frames are plotted, including the blue square and the rainbow dots. For day 2 only the blue rectangle is plotted, day 3 has only the rainbow dots, day 4 has the barplot from t2 data.frame only, and day 5 has the blue rectangle back. So definitely not what i am after.

Thanks, Monica