question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Composing Multiple Selections

See original GitHub issue

What is the best approach for combining multiple selections in Altair? In Vega-Lite this is described as such for a combined conditioned color selection:

"color": {
  "condition": {
    "selection": {"and": ["alex", "morgan"]},
    "aggregate": "count", "type": "quantitative"
  },
  "value": "grey"
}

And I can create a working example similar to the Vega-Lite docs as such in Altair:

import altair as alt
from vega_datasets import data

source = data.cars()

alex = alt.selection_interval(
    on="[mousedown[!event.shiftKey], mouseup] > mousemove",
    translate="[mousedown[!event.shiftKey], mouseup] > mousemove", 
    name='alex'
)
morgan = alt.selection_interval(
    on="[mousedown[event.shiftKey], mouseup] > mousemove",
    translate="[mousedown[event.shiftKey], mouseup] > mousemove",
    mark={"fill": "#fdbb84", "fillOpacity": 0.5, "stroke": "#e34a33"},
    name='morgan'
)

alt.Chart(source).mark_rect().encode(
    x='Cylinders:O',
    y='Origin:O',
    color=alt.condition({"selection": {"and": [alex.name, morgan.name]}}, 'count()', alt.ColorValue("grey"))    
).add_selection(
    alex, morgan
)

image

But it doesn’t feel very pythonic. I saw there is an alt.SelectionAnd() function, but I don’t know how it should work. I tried alt.SelectionAnd([alex.name, morgan.name]), but this returns:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-409c05815fbc> in <module>
----> 1 alt.SelectionAnd([alex.name, morgan.name])

TypeError: __init__() takes 1 positional argument but 2 were given

Some help, advice or insight is appreciated.

(I’m also not sure if the on and translate within the alt.selection_interval() function should be like this in Altair)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mattijncommented, Sep 25, 2019

I guess here: https://altair-viz.github.io/user_guide/interactions.html#selection-types-interval-single-multi. I should be able to add this example as a PR later this week, but this part:

morgan = alt.selection_interval(
    on="[mousedown[event.shiftKey], mouseup] > mousemove",
    translate="[mousedown[event.shiftKey], mouseup] > mousemove",
    mark={"fill": "#fdbb84", "fillOpacity": 0.5, "stroke": "#e34a33"},
    name='morgan'
)

is a bit verbose. But we can discuss this in that PR.

0reactions
jakevdpcommented, Sep 25, 2019

Great! Is there any place in the docs we could add this that you might have found before asking the question?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple choices in a list with compose
Multiple choices in a list with compose. Jetpack Compose is Android's modern toolkit for building native UI. It simplifies and accelerates ...
Read more >
How to implement list multiSelect in Jetpack Compose?
Show activity on this post. Add selected field to some class representing the item. Then just compose proper code based on that field....
Read more >
jetpack compose lazy column multiple item selection - YouTube
jetpack compose lazy column multiple item selection | jetpack compose lazycolumn items selectionToday we're going to make an example of ...
Read more >
Lazy Column Multiple Item Selection in Android Jetpack ...
In this Video We are going to Implement Multi Select Options in Lazy Column of Android Jetpack Compose.Build better apps faster with Jetpack ......
Read more >
14 RULES FOR WRITING MULTIPLE-CHOICE QUESTIONS
14 RULES FOR WRITING MULTIPLE-CHOICE QUESTIONS. 1. Use Plausible Distractors (wrong-response options). • Only list plausible distractors, even if the number ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found