Unable to index traces with a continuous legend using both add_trace and plotlyproxyinvoke "add_trace"
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 28/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, r
- Domain
- data-visualization
Research direction
Start with the supplied Shiny example using renderPlotly, plotlyProxyInvoke("addTraces"), and deleteTraces, and compare trace ordering when the continuous legend is created during rendering versus afterward. Reproduce the differing indexes and verify that adding and deleting the highlighted trace target the intended trace consistently.
Written by the indexing model from the issue text.
Description
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)
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from plotly/plotly.R
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
save_image Error Open
Difficulty 3/5 1-2 days Newbie friendliness 52/100
Similar issues
-
Difficulty 2/5 Half a day Newbie friendliness 78/100
ThinkR-open/datadiff#59 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
duckdb/duckdb-r#2773 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tidymodels/parsnip#1444 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100