我已尝试过链接中提到的这三种解决方案 Plotly: add_trace in a loop
但是我的代码仍然无效,代码只显示循环中的最终跟踪。
output$plot <- renderPlotly({
if(input$x == "M"){
my_x <- c(input$mmin:input$mmax)
number_of_cpgs <- 500*my_x
timetaken <- rep(0,input$mmax-input$mmin +1)
p<-plot_ly(y= timetaken, x= (number_of_cpgs) ,type="scatter", mode="markers+lines")
for(i in input$nmin:input$nmax){
for(j in input$kmin:input$kmax){
timetaken <- timemat[i,my_x,j]
p<-add_trace(p, y=~timemat[i,my_x,j], x=~(number_of_cpgs) , type="scatter",mode="markers+lines",visible = TRUE )
}
}
}
可重复的例子:
timemat <- array(c(1:1000), dim=c(10, 10, 10))
my_x <- c(1:10)
number_of_cpgs <- 500*my_x
timetaken <- rep(0,10)
p<-plot_ly(y= timetaken, x= (number_of_cpgs) ,type="scatter", mode="markers+lines")
for(i in 5:6){
for(j in 6:7){
timetaken <- timemat[i,my_x,j]
p <- add_trace(p, y=~timemat[i,my_x,j], x=~(number_of_cpgs) , type="scatter", mode="markers+lines", evaluate = TRUE)
}
}
p
答案 0 :(得分:1)