Black Lives Matter. Please consider donating to Black Girls Code today.

Dropdown input for Ckecklist output

Hi everyone!

This seems pretty basic, but I can’t figure out how to do it.
I have a Dropdown with 5 options that is an Input for a graph, but I want this same Dropdown to be an input for a Checklist. The Checklist has the same 5 options as the Dropdown, so I want the checklist box to be check when I select the option in the dropdown menu. Further on, I want to make a comparison between the options with the checklist, but it’s another story.

I looked at the Dash tutorial at this address: https://dash.plot.ly/getting-started-part-2, but don’t know how to adapt it with a checklist.

To do this, here is what my code looks like (I didn’t put everything it was very long):

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash()

option_species = {
"species1": "value1",
"species2": "value2",
"species3": "value3",
"species4": "value4",
"species5": "value5",
}

app.layout = html.Div([
html.Div([
    dcc.Dropdown(
        id="species-name",
        options=[
            {"label": key, "value": value} for key, value in option_species.items()
        ],
        value="value1"
    )
]),
html.Div([
    dcc.Checklist(
        id="species-checklist",
        options=[
            {"label": key, "value": value} for key, value in option_species.items()
        ],
        values=[]
    )
])
])

##### EDIT (solution )#####
@app.callback(
Output("species-checklist", "values"),
[Input("species-name", "value")]
)
def set_checklist(selected_value):
    return selected_value


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

Can someone tell what would be the callback?
Thank you guys!

Ok, I found it myself, it was not that complicated.

here is what the callback looks like, I will update the code above.

@app.callback(
Output("species-checklist", "values"),
[Input("species-name", "value")]
)
def set_checklist(selected_value):
    return selected_value