The make filter change handler (f) message to the data filter object will evaluate the user function argument f every time the data filter is changed. Create the function to remove the reference line if it exists, find the mean of the response for the rows selected by the local data filter and that are not excluded, then add a reference line to the Y axis at the mean of the response for those rows. Then send the message to the data filter.
//user function to be called when filter is changed
f = function({a}, //a is not used
//remove the y axis reference line, if it exists
try(report(gb)[axisbox(2)] << remove ref line(meanHeight));
//get the where clause from the data filter
//it will look like Select Where(...)
txt = df << get where clause;
//get the argument, if it exists
arg = if(length(txt), arg(parse(txt), 1), txt);
//get row numbers of filtered rows
aaDf = if(length(txt),
associative array(dt << get rows where(arg)),
index(1, nrow(dt))
);
//find row numbers of non-excluded rows
vecEx = dt << select excluded
<< invert row selection
<< get selected rows
<< clear select;
aaEx = associative array(vecEx);
//get row numbers of both
aaEx << intersect(aaDf);
lstAll = aaEx << get keys;
//find the mean of filtered/non-excluded response
//if nothing is filtered, find the mean of non-excluded only
meanHeight = if(length(txt),
mean(column(dt, "height")[lstAll]),
mean(column(dt, "height")[aaEx << get keys])
);
//add reference line
report(gb)[axisbox(2)] << add ref line(meanHeight, "Solid", 19, 2);
);
rs = df << make filter change handler(f);