Add recatangles in a loop in plotly

for (i in 1:nrow(histfolder)) {
x0[i] <- min(histfolder[[5]][[i]]$offset)
x1[i] <- max(histfolder[[5]][[i]]$offset)
y0[i] <- hist_percentiles[[4]][[i]]
y1[i] <- hist_percentiles[[5]][[i]]

p1 <- p1 %>%
layout(shapes = list(
list(
type = "line",
line = list(color = "red"),
x0 = 0,
x1 = max(ae_combined$offset),
xref = 'paper',
y0 = UQTL,
y1 = UQTL,
yref = "y"
),
list(
type = "line",
line = list(color = "red"),
x0 = 0,
x1 = max(ae_combined$offset),
xref = 'paper',
y0 = QTL,
y1 = QTL,
yref = "y"
),
list(
type = "rect",
line = list(color = "blue"),
x0 = x0[[i]],
x1 = x1[[i]],
xref = 'x',
y0 = y0[[i]],
y1 = y1[[i]],
yref = "y"
)
)
)
}

I am trying to add multiple rectangles by using shapes in a loop in plotly, but unable to do so. Only the first shape in the loop is getting reflected. Can somebody advice me how to get this done?

@Sukalpo, please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. That will allow someone with the plotly expertise I lack to more readily help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.