Change position of circle shape while keeping line shape fixed

I am trying to create a plotly object having bunch of circle and line shapes. Goal is to have the ability to drag the circle shapes, but not the line shapes. Here is the code snippet which plots the line shapes and circle shapes along with the ability to drag them. I want the line shapes to be fixed (or non-draggable). Thank you.

library(plotly)
library(purrr)

set.seed(1)
n <- 10

ee <- data.frame(cbind(seq(0,0.9, length.out = n),
                       seq(0,0.9, length.out = n),
                       seq(0.05,0.95, length.out = n),
                       seq(0.05,0.95, length.out = n)))

names(ee) <- c("x0", 'y0', "x1", "y1")                 
                 
pp <- cbind(runif(10), runif(10))

# creates a list of n circle shapes 
circles <- map2(pp[,1], pp[,2], 
                ~list(
                  type = "circle",
                  xanchor = .x,
                  yanchor = .y,
                  x0 = -4, x1 = 4,
                  y0 = -4, y1 = 4,
                  xsizemode = "pixel", 
                  ysizemode = "pixel",
                  fillcolor = "blue",
                  line = list(color = "transparent")
                )
)

# creates a list of n line shapes 
lines <- pmap(ee,
              function(x0, y0, x1, y1) {
                list(
                  type = "line",
                  line = list(color = "red",
                              width = 0.5),
                  x0 = x0,
                  x1 = x1,
                  y0 = y0,
                  y1 = y1)
              }
)

plot_ly() %>%
  layout(shapes = c(lines, circles)) %>%
  config(edits = list(shapePosition = TRUE))

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