Skip to content

Subscript out of bounds error when trying to combine segment and markers with frame #1618

Closed

Description

@awgymer

I am attempting to make an animated dumbbell chart in plotly with R.

Following the example here and using the info here, I came up with the following code:

    df <- data.frame(
      category=c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'),
      year=c(2000, 2000, 2000, 2000, 2001, 2001, 2001, 2001),
      val_a=c(1,2,2,1,2,5,6,8),
      val_b=c(3,5,4,7,1,9,2,12)
    )
    
    plot_ly(data = df, frame = ~year) %>%
      add_markers(x = ~val_a, y = ~category, name = "Val_A", color = I("red")) %>%
      add_markers(x = ~val_b, y = ~category, name = "Val_B", color = I("blue")) %>%
      add_segments(x = ~val_a, xend = ~val_b, y = ~category, yend = ~category, showlegend=F) %>%
      layout(
        title = "Val A v Val B",
        xaxis = list(title = "Value"), 
        yaxis = list(title = ""),
        margin = list(l = 65)
    )  

Unfortunately this throws the following error:

    Error in which(idx)[[1]] : subscript out of bounds
    18.
    registerFrames(p, frameMapping = frameMapping)
    17.
    plotly_build.plotly(instance)
    16.
    instance$preRenderHook(instance)
    15.
    createPayload(x)
    14.
    toJSON(createPayload(x))
    13.
    widget_data(x, id)
    12.
    htmltools::tagList(container(htmltools::tagList(x$prepend, widget_html(name = class(x)[1], package = attr(x, "package"), id = id, style = style, class = paste(class(x)[1], "html-widget"), width = sizeInfo$width, height = sizeInfo$height), x$append)), widget_data(x, id), if (!is.null(sizeInfo$runtime)) { ...
    11.
    toHTML(x, standalone = standalone)
    10.
    as.tags.htmlwidget(x, standalone = TRUE)
    9.
    htmltools::as.tags(x, standalone = TRUE)
    8.
    isTag(ui)
    7.
    rewriteTags(x, function(uiObj) { if (isTag(uiObj) || isTagList(uiObj) || is.character(uiObj)) return(uiObj) else return(tagify(as.tags(uiObj))) ...
    6.
    tagify(x)
    5.
    renderTags(html)
    4.
    save_html(html, file = index_html, background = background, libdir = "lib")
    3.
    html_print(htmltools::as.tags(x, standalone = TRUE), viewer = if (view) viewerFunc)
    2.
    print.htmlwidget(x)
    1.
    (function (x, ...) UseMethod("print"))(x)

However, if you run the plot code with either the markers or the segments, it works fine. Why then can I not seem to combine them?

Activity

  1. nitram9 commented on Oct 23, 2020

    @nitram9

    Just wanted to let you know that I have the same thing happening on my end. Have not yet figured out why both markers and lines work separately but when together, the error is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions