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.

Add blank dropdown option that doesn't filter

See original GitHub issue

I have a chart with a dropdown selector, and the selection is responsible for filtering the data displayed in the chart. I’m trying to add a “blank” option to the binding_select that will result in no filtering (i.e. “display all data”). Is there an easy way to do that?

I was looking at alt.condition and filter predicates, but wasn’t able to figure it out. I was playing with the following example, where i’d want an “All” selection in the binding_select:

import altair as alt
from vega_datasets import data


cars = data.cars.url

input_dropdown = alt.binding_select(options=['All', 'Europe','Japan','USA'])
selection = alt.selection_single(fields=['Origin'],
                                 bind=input_dropdown,
                                 name='Country of ',
                                 init={'Origin': 'Europe'})
color = alt.condition(selection,
                    alt.Color('Origin:N', legend=None),
                    alt.value('lightgray'))

alt.Chart(cars).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
    color='Origin:N',
    tooltip='Name:N'
).add_selection(
    selection
).transform_filter(
    selection
   # Looking for something like <no filter> if selection == 'All' else selection
)

Thanks for the library and for the help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Apr 18, 2020

Oh, sorry, you have to use selection names that are valid identifiers. Try this:

import altair as alt
from vega_datasets import data

cars = data.cars.url

input_dropdown = alt.binding_select(options=['All','Europe','Japan','USA'], name="Country")
selection = alt.selection_single(fields=['Origin'],
                                 bind=input_dropdown,
                                 init={'Origin': 'Europe'})

alt.Chart(cars).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
    color='Origin:N',
    tooltip='Name:N'
).add_selection(
    selection
).transform_filter(
   f"({selection.Origin}[0] == 'All') || ({selection.Origin}[0] == datum.Origin)"
)
0reactions
joelostblomcommented, Feb 23, 2021

@ZaxR I am going through Altair issues to find those that have been resolved and can be closed. It looks to me like this issue has been solved so I am closing it, but please feel free to reopen and add a comment if there is something you don’t think is resolved yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding A Blank Option in a Data Validation Drop Down List in ...
Today we will walk through a couple of ways you can achieve adding a blank/empty value to the beginning of your Data Validation...
Read more >
How to Add a Blank Item in a Drop-Down List in Excel - YouTube
In this video, I demonstrate how to add a ' blank ' option to a data validation drop-down list in Excel. The '...
Read more >
How to Add Blank Option to Drop Down List in Excel (2 Methods)
1. Use Empty Cell as Reference to Add Blank Option in Excel Drop Down List. In this method, I will add a blank...
Read more >
Adding All or Blank option to dropdown list
Solved: Hi I've created a Dropdown box to filter gallery contents. The dropdown gets its contents from a SharePoint list.
Read more >
How To Add A Blank Value To A Dropdown List In Power Apps
But after enabling AllowEmptySelection the confusing part is once a user clicks to view the dropdown list there is no blank option at...
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