"Select All" Option within st.checkbox

Hi All,

New to Streamlit and apolagise if this question has been answered before, but I could not see a solution for a st.checkbox only for st.multiselect.

I would like to filter a dataframe by year using a st.checkbox with an option within the st.checkbox that a user can select โ€œshows allโ€. This will will find the unique values, sort them and then add the ALL item at the start, so the user could remove the filter. This follows on from the topic here Bring your Jupyter Notebook to life with interactive widgets | by Semi Koen | Towards Data Science

The code is as follows:
df data is here: Number of International Visitors to London โ€“ London Datastore

ALL = 'ALL'
def unique_sorted_values_plus_ALL(array):
    unique = array.unique().tolist()
    unique.sort()
    unique.insert(0, ALL)
    return unique
dropdown_year = widgets.Dropdown(options =    unique_sorted_values_plus_ALL(df.year))
def dropdown_year_eventhandler(change):
    if (change.new == ALL):
        display(df)
    else:
        display(df[df.year == change.new])
dropdown.observe(dropdown_year_eventhandler, names='value')
st.write(df.describe)

However, when using the observe function to elevate the change the following error occurs

AttributeError: 'str' object has no attribute 'observe'

Any help would be much appreciated! Alternatively an alternative would also be helpful.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.