Targeting customdata in transform

Greetings, I’m trying to plot multiple lines and then filter them using transform. I wanted to add tags to each line using customdata, however I’m unable to target the atr1. I tried ~atr1 / “atr1” / ~“atr1” / customdata[[1]] … and can’t find the way, to adress the issue.

y1 <- rnorm(5)
y2 <- rnorm(5)
y3 <- rnorm(5)

p <- plotly_empty(x = seq(1,5),
transforms = list(
type = ‘filter’,
target = “atr1”,
operation = ‘=’,
value = 1

p <- add_trace(p, y = y1, name = ‘line 1a’,mode = ‘lines’, customdata = list(atr1 = 1, atr2 = “a”))
p <- add_trace(p, y = y2, name = ‘line 2a’,mode = ‘lines’, customdata = list(atr1 = 2, atr2 = “a”))
p <- add_trace(p, y = y3, name = ‘line 1b’,mode = ‘lines’, customdata = list(atr1 = 1, atr2 = “b”))

Here’s how (in JS):

1 Like

Thank you very much. This targeting work, when there is only one element per object. I would like to have more atributes in customdata, for multiple filtering. I played a little with your example and didn’t manage to make it work with more customdata values per point.
it seems to work correctly when: customdata[0], but incorrectly, when customdata[1]

Plotly.newPlot(‘graph’, [{
x: [1, 2, 3],
y: [1, 2, 1],
customdata: [[1,1], [1,0], [0,1]],
transforms: [{
type: ‘filter’,
target: ‘customdata[1]’,
operation: ‘=’,
value: 1

Sorry to revive this topic but it’s my exact question too. How do you specify an element of customdata as the target for a transform?

In my case I’m storing an array of objects in customdata and want to use one of the named members as the filter/group target. Something like [{“value”:10, “other”: “things”},{“value”:20, “other”: “also”},{“value”:30, “other”: “apply”}]. How would I filter for value == 20?

Nevermind I think I figured it out.

I combined the codepen above with the lessons learned here:

The trick was the part where you can provide an array as the target instead of just a string describing a property of the trace (such as x, y, or customdata)