plotly / plotly/plotly.R

Unable to index traces with a continuous legend using both add_trace and plotlyproxyinvoke "add_trace"

Đang mở
#2,390 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
R
Star
2.7k
Fork
641
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I have a number of plots that I am trying to synchronize and draw a highlighted point on in response to a users search. This works fine except when they are in tabs. Plotly proxy can't add a trace to graph that is not yet drawn, and in Shiny there isn't a good way to trigger an event after the plot is drawn. Subsequently I have added a manual add_trace check to see if a search has found a point that needs to be highlighted. However, when I add a trace directly to the figure. The traces are added in different orders, I gather the legend is added after both traces are defined. It appears that a continuous legend gets added as a trace, after all traces are drawn. So in a different order than when invokeProxy.

So in scenario one when a plot has been drawn and I add a trace the new trace has an index of 2, however if I draw the plot then add it within the same render function the legend has an index of 2.

It's really difficult to generate a reproducible example here, as I have done a number of tests, and things are pretty confusing. For example, if I add a name variable. name= ~SERIAL_NUM then for some reason each point gets it's own trace index. However, this obliterates the hover text for some reason.

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("plot"),actionButton(label="add","addtrace"),actionButton(label="delete","deletetrace")
)




server <- function(input, output, session) {
   plotproxy <- plotlyProxy("plot", session=session, deferUntilFlush=FALSE)
 
  
  output$plot <- renderPlotly({
    a = seq(1,10,1)
    b = seq(100,1000,100)
    c = seq(1,4.9,0.4)
    
    data = tibble(a,b,c)
    data <- data %>% mutate(res = a+b+c)
    
    layout_details <- list(xaxis = list(title = 'a [-]'),
                           yaxis = list(title = 'b [-]'),
                           zaxis = list(title = 'c [-]'),
                           coloraxis=list(colorbar=list(title=list(text='Here are the results'))))
    
    p = plot_ly(data, x = ~a, y = ~b , color = ~res, type = 'scatter', 
                mode = 'markers', text = ~res, showlegend = FALSE, scene = 'scene1',hovertemplate = paste('<b><b>SERIAL_NUM</b>:  %{text}'))
    p
  })
  

  observeEvent(input$addtrace, {
    plotproxy%>%plotlyProxyInvoke("addTraces", list(list( 
      x =  list(2),
      y = list(2),
      type = 'scatter',
      mode = 'markers' ,
      marker = list(size = 10,
                    color = 'rgba(255, 18 , 19 , .9)',
                    line = list(color = 'rgba(0, 0, 0, .3)',
                                width = 3))
    )))
    
  
  
})
  observeEvent(input$deletetrace, {
    plotproxy%>%plotlyProxyInvoke("deleteTraces",2)
    
    
  })
}
shinyApp(ui, server)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với ví dụ Shiny được cung cấp bằng cách sử dụng renderPlotly, plotlyProxyInvoke("addTraces") và deleteTraces, rồi so sánh thứ tự của các trace khi chú giải liên tục được tạo trong quá trình render so với khi được tạo sau đó. Tái hiện các index khác nhau và xác minh rằng việc thêm và xóa trace được đánh dấu luôn nhắm đến đúng trace dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, r
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.