The Wayback Machine - https://web.archive.org/web/20201217175143/https://github.com/ropensci/plotly/issues/1903
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error subscript out of bounds: registerFrames with simple and cumulative animation on same plot #1903

Open
frseguin opened this issue Dec 15, 2020 · 1 comment

Comments

@frseguin
Copy link

@frseguin frseguin commented Dec 15, 2020

When producing a plot with both cumulative and non-cumulative animations on the same plot where I assign names to both traces, I get the error
Error in which(idx)[[1]] : subscript out of bounds
when trying to print the plot. I've debugged the issue and I think I isolated the problem, although I am not sure on how to fix it.

I believe the problem is here:

traceNamesMissing <- setdiff(frameTraceNames, sapply(d, "[[", "name"))

I think traceNamesMissing is supposed to hold the names of the traces that are missing on the particular frame d, but present on other frames. However, when debugging, frameTraceNames is a list of unique trace names but
sapply(d, "[[", "name")
produces a list of character vectors in my situation, and therefore traceNamesMissing gets assigned with the name of all the traces of the plot. For my particular situation, I've been able to resolve the issue by replacing line 484 with

 traceNamesMissing <- setdiff(frameTraceNames, unlist(sapply(d, "[[", "name")))

However, since I am not that familiar with the internal workings of the package I don't think this solution can work for all cases.

Here is my reprex.

suppressMessages(library(tidyverse))
suppressMessages(library(plotly))
df1<- tibble(frame = seq(1:10)) %>% mutate(x = row_number(), y = 0)
df2<- tibble(rowid = seq(1:10)) %>% mutate(x = row_number(), y = 1) %>%
  split(.$rowid) %>%
  accumulate(function(old, new){
    bind_rows(old, new)
  }) %>%
  bind_rows(.id = "frame") %>%
  mutate(frame = as.numeric(frame))
  


p_noNames<- plot_ly(df1, type = "scatter") %>%
  add_trace(mode = "markers", x = ~x, y = ~y, frame = ~frame) %>%
  add_trace(data = df2, mode = "lines", x = ~x, y = ~y, frame = ~frame)
out_noNames<- plotly_build(p_noNames)
#> No scatter mode specifed:
#>   Setting the mode to markers
#>   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode

p_withNames<-  plot_ly(df1, type = "scatter") %>%
  add_trace(mode = "markers", x = ~x, y = ~y, frame = ~frame, name= "A") %>%
  add_trace(data = df2, mode = "lines", x = ~x, y = ~y, frame = ~frame, name = "B")
out_withNames<- plotly_build(p_withNames)
#> No scatter mode specifed:
#>   Setting the mode to markers
#>   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
#> Error in which(idx)[[1]]: subscript out of bounds
@frseguin
Copy link
Author

@frseguin frseguin commented Dec 15, 2020

Issue #1618 might be related to this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.