I have a plot, where I like to shift a vertical line. So far I achieved this by adding shapes to a plotly plot and using
plotly::config(editable = TRUE). But when I enable editable = TRUE i am not able to switch on/off the traces by clicking corresponding legend entry. The first plot in the code is with option editable = TRUE. The second plot is without editable = TRUE.
library(shiny)
library(plotly)
lines <- list()
line <- list(
type = "line",
line = list(color = "pink"),
xref = "x",
yref = "y"
)
x <- 1:20
y <- 1:20
for (i in seq(1,max(x),length.out = 5)) {
line[["x0"]] <-i
line[["x1"]] <- i
line[c("y0", "y1")] <- c(-100,100)
lines <- c(lines, list(line))
}
ui <- fluidPage(
plotlyOutput("p1"),
plotlyOutput("p2")
)
server <- function(input, output, session) {
output$p1 <- renderPlotly({
p<- plot_ly(source = "plot_time_series") %>%
layout( shapes =lines) %>%
plotly::config(editable = TRUE)
for (i in seq(10)){
p <- p %>% add_lines(x=x,
y=y+1,
name = i)
}
return(p)
})
output$p2 <- renderPlotly({
p<- plot_ly(source = "plot_time_series") %>%
layout( shapes =lines)
for (i in seq(10)){
p <- p %>% add_lines(x=x,
y=y+1,
name = i)
}
return(p)
})
}
runApp(list(ui = ui, server = server),launch.browser = TRUE)