altair icon indicating copy to clipboard operation
altair copied to clipboard

Access to slider.value

Open liquidcarbon opened this issue 3 years ago • 1 comments

It's been suggested in https://github.com/altair-viz/altair/pull/1599 and in here to provide easy/easier access to slider.value. Have you had a chance to tackle this?

Not having slider.value, I'm looking for alternatives. From https://altair-viz.github.io/user_guide/transform/filter.html#selection-predicates

Selection predicates can be used to filter data based on a selection. While these can be constructed directly using a SelectionPredicate class, in Altair it is often more convenient to construct them using the selection() function. For example, this chart uses a multi-selection that allows the user to click or shift-click on the bars in the bottom chart to select the data to be shown in the top chart

  1. Could you give an example of using SelectionPredicate class?
  2. is it possible to use the selector value in chart title, e.g. alt.Chart(df, title=f"points greater than {selector.value}")

liquidcarbon avatar Sep 08 '22 02:09 liquidcarbon

  1. I don't think that class is used directly, rather you use alt.selection_ as in the documentation you linked
  2. You can't have dynamic axis title/labels https://github.com/altair-viz/altair/issues/2011#issuecomment-597781332, but you could use mark_text as a workaround similar to https://stackoverflow.com/questions/71210072/can-i-turn-altair-axis-titles-into-links/71210807#71210807.

joelostblom avatar Sep 08 '22 02:09 joelostblom

Does this mean that a chart like one isn't possible with Altair?

image

https://vega.github.io/vega-lite-v4/docs/text.html#properties That's from V4 but uses "params" in the chart spec which as far as I can tell was undocumented in V4.

Is there any way to manually add to the chart spec that Altair produces? Like:

chart = alt.Chart(...)

chart.hack_hack({"params": ...)

davidgilbertson avatar Feb 03 '23 05:02 davidgilbertson

It will be in the upcoming Altair v5, sneak peak of docs of this example: https://joelostblom.github.io/altair-docs/user_guide/marks/text.html

Now, you can do chart.to_dict() to serialize it to a Vega-Lite specification that you can modify to your needs like a normal dictionary. But you won't be able to render it anymore in Altair v4.

mattijn avatar Feb 03 '23 07:02 mattijn

OK cool, thanks!

davidgilbertson avatar Feb 03 '23 19:02 davidgilbertson