plotly / plotly/plotly.R

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

Abierto
#2,390 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
R
Estrellas
2.7k
Forks
641
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comience con el ejemplo de Shiny proporcionado usando renderPlotly, plotlyProxyInvoke("addTraces") y deleteTraces, y compare el orden de los traces cuando la leyenda continua se crea durante el renderizado frente a cuando se crea después. Reproduzca los índices diferentes y verifique que añadir y eliminar el trace resaltado apunte de forma consistente al trace previsto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, r
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.