# Drop down with Checkboxes:

**URL:** <https://community.plotly.com/t/drop-down-with-checkboxes/21549>\
**Category:** Dash Python\
**Created:** [March 28, 2019, 7:20pm UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549 "2019-03-28T19:20:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhanu.kolli](https://avatars.discourse-cdn.com/v4/letter/b/c57346/32.png) [@bhanu.kolli](https://community.plotly.com/u/bhanu.kolli)\
**Post date:** [March 28, 2019, 7:20pm UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/1 "2019-03-28T19:20:14Z")

</div>

Hi all, I am trying to create a drop down with html.Div and in that I need to select for multiple values using the checkbox for each of the value and connect it to update section. Please provide a simple example for me so that I can go through.Here is the sample output of the image:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/3d41d85d8039b68d67018e149a3fb3e142aa82de.png)

---

<div class="post-metadata">

**Author:** ![tcbegley](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@tcbegley](https://community.plotly.com/u/tcbegley)\
**Post date:** [March 28, 2019, 8:05pm UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/2 "2019-03-28T20:05:07Z")

</div>

I’m not aware of existing components that can achieve exactly this, but you can get pretty close with the `Dropdown` component in _dash-core-components_. Just set `multi=True`. See [here](https://dash.plot.ly/dash-core-components/dropdown) for the documentation.

---

<div class="post-metadata">

**Author:** ![rasoolsk](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rasoolsk](https://community.plotly.com/u/rasoolsk)\
**Post date:** [August 24, 2020, 11:11am UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/3 "2020-08-24T11:11:32Z")

</div>

Hi Bhanu… Were you able to find a way to achieve Dropdown with checkboxes? I am also looking for similar feature.

Regards  
Rasool

---

<div class="post-metadata">

**Author:** ![pokgak](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/pokgak/32/16341_2.png) [@pokgak](https://community.plotly.com/u/pokgak)\
**Post date:** [August 29, 2020, 11:21am UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/4 "2020-08-29T11:21:53Z")

</div>

Not with the same UI but you could achive the same functionality (selecting multiple values in a dropdown) by setting the `multi` property of `dcc.Dropdown` to `True`. See [Multi-value dropdown](https://dash.plotly.com/dash-core-components/dropdown)

---

<div class="post-metadata">

**Author:** ![kkc32](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kkc32](https://community.plotly.com/u/kkc32)\
**Post date:** [February 17, 2021, 12:17am UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/5 "2021-02-17T00:17:48Z")

</div>

I have found that the multi option works, but for my app, I would rather have the check boxes because all of the items that I want to select do not fit in the box! So it’s hard to tell what has and has not been selected… ☹

---

<div class="post-metadata">

**Author:** ![pkozilek](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pkozilek](https://community.plotly.com/u/pkozilek)\
**Post date:** [March 8, 2021, 6:45pm UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/6 "2021-03-08T18:45:01Z")

</div>

Hi,

You can use a _dcc.Checklist_ inside a _dbc.DropdownMenu_, like this:

```auto
html.Div(
    children=dbc.DropdownMenu(
        children=[
            dcc.Checklist(
                options=[],
                value=[],
            ),
        ],
        label="menu",
    ),
)

```

It’s not a perfect solution but it works.

Documentation:  
[dbc.DropdownMenu](https://dash-bootstrap-components.opensource.faculty.ai/docs/components/dropdown_menu/)  
[dcc.Checklist](https://dash.plotly.com/dash-core-components/checklist)

---

<div class="post-metadata">

**Author:** ![rohith](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@rohith](https://community.plotly.com/u/rohith)\
**Post date:** [June 1, 2021, 10:07am UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/7 "2021-06-01T10:07:28Z")

</div>

Do you know how to adjust the width and height for dbc.DropdownMenu component?  
do we have something like a style to control the height and width similar to dcc.dropdown?

---

<div class="post-metadata">

**Author:** ![zinovii](https://avatars.discourse-cdn.com/v4/letter/z/3ec8ea/32.png) [@zinovii](https://community.plotly.com/u/zinovii)\
**Post date:** [May 9, 2024, 6:33pm UTC](https://community.plotly.com/t/drop-down-with-checkboxes/21549/8 "2024-05-09T18:33:33Z")

</div>

Recently I needed something similar and used another approach (aka filtering by Google Sheets). Styling must be improve.

```auto

import dash
from dash import html, dcc, no_update, ctx, State
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
from dash_iconify import DashIconify
import dash_ag_grid as dag
import pandas as pd

full_filter_icon = DashIconify(
      icon="bx:filter",
      color="green",
      width=30,
      height=30
)

partial_filter_icon = DashIconify(
      icon="prime:filter-fill",
      color="green",
      width=20,
      height=20
)

checklist_all_values = [i for i in range(1, 21)]

filter = html.Div([
        dbc.Row([
            dbc.Col(dbc.Button("Select All", id='select-all-button', n_clicks=0, color="link")),
            dbc.Col(dbc.Button("Clear", id='clear-button', n_clicks=0, color="link"))
        ]),
        dbc.Row([
            dbc.Col(dbc.Input(id='input-value')),
              ]),
        dbc.Row([
            dbc.Col(
            dcc.Checklist(
            options=[{"label": f"Option {i}", "value": i} for i in range(1, 21)],
            value=checklist_all_values,
            id="checklist",
            style={'maxHeight': '180px', 'overflowY': 'scroll', 'accent-color': 'transparent'}))
        ]),
      dbc.Row([
        dbc.Col(dbc.Button("Cancel", id='cancel-button', outline=True, color="secondary", className="me-1")),
        dbc.Col(dbc.Button("Apply", id='apply-button', outline=True, color="success", className="me-1")),
        ],
        justify='end')
        ])

popover = html.Div(
        [
        dbc.Button(id="popover-target", children=full_filter_icon, n_clicks=0, color=None, style={'background-color': 'transparent', 'border': 'none'}),
        dbc.Popover(
            id='popover',
            children=filter,
            target="popover-target",
            body=True,
            trigger="click",
            placement='right',
                )
            ]
        )

# Define the data for the grid
ag_grid_data_df = pd.DataFrame([{"id": i, "value": i} for i in range(1, 21)], columns=['id', 'value'])

# Define the column definitions for the grid
ag_grid_column_defs = [
{"headerName": "ID", "field": "id", "sortable": True, "filter": True},
{"headerName": "Option", "field": "value", "sortable": True, "filter": True, "valueFormatter": {"function": "'Option ' + params.value"}}
]

# Create the AG Grid component
ag_grid = dag.AgGrid(
id='my-ag-grid',
rowData=ag_grid_data_df.to_dict('records'),
columnDefs=ag_grid_column_defs
)

app = dash.Dash( __name__ , external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container([
    dbc.Row([
       dbc.Col(popover, width=5)
    ], justify="end"),
    dbc.Row([
        dbc.Col(ag_grid, width=5)
    ], justify="center"),
    dcc.Store(id='store-checklist-value', storage_type='memory')
    ])

@app.callback(
    Output("my-ag-grid", "rowData"),
    Input("store-checklist-value", 'data'),
)
def update_ag_grid(data):
  if data is not None:
    return ag_grid_data_df[ag_grid_data_df["value"].isin(data)].to_dict('records')
  return no_update

@app.callback(
    [Output("checklist", "options"), Output("checklist", "value")],
    Input("input-value", 'value'),
    prevent_initial_call=True
)
def update_checklist_by_input(value):
  if value is not None:
    return [{"label": f"Option {i}", "value": i} for i in range(1, 21) if value in f"Option {i}"], []

@app.callback(
    [Output("popover", "is_open"), Output("checklist", "value", allow_duplicate=True), Output("popover-target", "children"), Output("store-checklist-value", "data")],
    [Input("select-all-button", 'n_clicks'), Input("clear-button", "n_clicks"), Input("cancel-button", 'n_clicks'), Input("apply-button", "n_clicks")],
    [State("checklist", "options"), State("checklist", "value")],
    prevent_initial_call=True
)
def update_popover(select_all_button_n_clicks, clear_button_n_clicks, cancel_n_clicks, apply_n_clicks, options, value):

  if ctx.triggered_id == 'select-all-button':
    return no_update, checklist_all_values, no_update, no_update

  elif ctx.triggered_id == 'clear-button':
    return no_update, [], no_update, no_update

  elif ctx.triggered_id == 'cancel-button':
    return False, checklist_all_values, full_filter_icon, checklist_all_values

  elif ctx.triggered_id == 'apply-button':
    if len(value) == len(checklist_all_values):
      return False, no_update, full_filter_icon, value
    else:
      return False, no_update, partial_filter_icon, value

  return no_update

if __name__ == ' __main__':
  app.run_server(debug=True)

```
