Groupby + filter : show count of points in scatter plot

Dear Everyone,

We are using Plotly transform to filter points on a scatterplot. We followed the example on: https://plot.ly/python/multiple-transforms/#filter-and-group-by

Now, we are trying to add the count of the visible points to the legend labels. We checked the API and only found groupby.nameformat

What would the best way to achieve something like this:

AFTER MEAL HIGH is the label and the (3) in the bracket is the count we want to obtain.

Thank you,
Best Regards,
Arindam

Probably the easiest way would be to override the groupby trace names. See example: https://codepen.io/etpinard/pen/bLQbWO?editors=0010

Thank you. We already do that when the graph is rendered. But we want the count to be updated live based on the number of visible points on the graph, when the filter is applied. We have a user interaction in place that updates the date filter and it would be useful for the users to see how many data points match the date range they’ve selected.
Therefore, we need to rename the labels after the plot has been rendered using the new count. Is that possible?

Your example seems to point in the right direction, but is there some kind of variable interpolation or callback we could use to show the number of points as part of the legend label?