使用customdata

时间:2018-08-01 20:23:37

标签: r filtering plotly

我正在制作交互式折线图。我为每一行提供了多个功能,并且我希望能够根据所选功能来选择应显示的功能。我尝试将customdata添加到每个跟踪并根据其值进行过滤。在我向自定义数据添加更多参数之前,它一直有效。我找不到如何指定哪个参数

带有一个参数的R示例:

    library("plotly")
    y1 <- rnorm(6)
    y2 <- rnorm(6)
    y3 <- rnorm(6)

    p <- plotly_empty(
      transforms = list(
        list(
          type = 'filter',
          target = 'customdata',
          operation = '=',
          value = 1
        )
      )
    )

    p <- add_trace(p, x = c(1:6), y = y1, name = 'line 1',mode = 'lines', customdata = 1)
    p <- add_trace(p, x = c(1:6), y = y2, name = 'line 2',mode = 'lines', customdata = 1)
    p <- add_trace(p, x = c(1:6), y = y3, name = 'line 3',mode = 'lines', customdata = 0)
    p

具有一个参数的非工作R示例: (我尝试使用向量,双括号,$运算符,命名元素,我想都没想到,也找不到任何文档,自定义数据和定位如何工作)

    p <- plotly_empty(
      transforms = list(
        list(
          type = 'filter',
          target = 'customdata[[1]]',
          operation = '=',
          value = 1
        )
      )
    )

    p <- add_trace(p, x = c(1:6), y = y1, name = 'line 1',mode = 'lines', customdata = list(1,1))
    p <- add_trace(p, x = c(1:6), y = y2, name = 'line 2',mode = 'lines', customdata = list(0,1))
    p <- add_trace(p, x = c(1:6), y = y3, name = 'line 3',mode = 'lines', customdata = list(1,0))
    p

0 个答案:

没有答案