将列表插入到 plotly dash 下拉列表中,导致下拉列表为空

insertion of list to a plotly dash dropdown resulting in empty dropdown

我一直在观看各种使用破折号核心组件创建下拉菜单的教程。我能够重新创建 youtube tutorial. The only thing I changed from that working code was that I replaced the dictionary within the options argument to a list of species that I would like the user to be able to choose from. I am okay with the label being the same as the value in the case of all the species and so I don't believe that I need the dictionary as per dash plotly dropdown documentation.

中演示的那个

我无法在 options 参数中插入列表的原因是什么?是变量名的形式还是实际列表本身?

预期结果: 插入工作代码的列表会创建一个包含列表所有元素的下拉列表

实际结果: 下拉列表创建时没有错误但为空

以下是未生成下拉值的代码:

app.layout = html.Div([
    
    dcc.Dropdown(
        id = 'first-dropdown',
        options = [species],                #where species = long list of strings
        value = 'Pacific Water Shrew'       #one of the strings contained in species
    )
])

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

我确定有一个简单的修复方法,但我在这里有点难过。
提前致谢!

根据评论,如果 species 是列表,则 [species] 是列表的列表。只需传递列表即可。还要注意拼写错误,您评论中列表中的值与 value 参数不一致。

from dash import html, dcc
import dash

# Build App
# app = JupyterDash(__name__)
app = dash.Dash()
species = ['Pacific Water Shrew','Whihtebark Pine']
app.layout = html.Div(
    [
        dcc.Dropdown(
            id="first-dropdown",
            options=species,  # where species = long list of strings
            value="Pacific Water Shrew",  # one of the strings contained in species
        ),
        html.Pre(dash.__version__)
    ]
)

app.run_server()