简体   繁体   English

标签未显示在 Dash Dropdown 中

[英]Labels not displaying in Dash Dropdown

I have two separate Dash dropdowns I am trying to create and the second one (id= 'select_range' is not displaying the option labels when I run the app.我有两个单独的 Dash 下拉列表,我正在尝试创建第二个(当我运行应用程序时,id= 'select_range' 不显示选项标签。

The error I am receiving:我收到的错误:

Invalid argument `options` passed into Dropdown with ID "select_range".
Expected one of type [object].
Value provided: 
[
  {
    "Label": "Last 12 months",
    "value": 12
  },
  {
    "Label": "Last 6 months",
    "value": 6
  },
  {
    "Label": "Last month",
    "value": 1
  }
]
from dash import Dash
from dash.dependencies import Input,Output
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc

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

app.layout = html.Div([
    html.H1("My Budget Report", style={'text-align': 'center', 'color': 'white'}),

    html.Div([
        html.Div([
            dcc.Dropdown(id="select_visual",
                         options=[
                             {"label": "Income_Expense", "value": 'Income_Expense'},
                             {"label": "Expense_Breakdown", "value": 'Expense_Breakdown'},
                             {"label": "Monthly_Expenses", "value": 'Monthly_Expenses'}],
                         multi=False,
                         value='Income_Expense',
                         style={'width': "60%"},
                         placeholder='Please select...',
                         clearable=False)], className='six columns'
        ),
        html.Div([
            dcc.Dropdown(
                id="select_range",
                options=[
                    {"Label": "Last 12 months", "value": 12},
                    {"Label": "Last 6 months", "value": 6},
                    {"Label": "Last month", "value": 1}],
                multi=False,
                value='Last 12 months',
                style={'width': '60%', 'margin-left': '295px'}
            ), ], className='six columns',
        )
    ], className= 'row'),



    html.Div(
        dcc.Graph(
                id='Graphs', figure={},style={'height':'80vh'}
                    ))

])

You use "Label" key, while you need to use "label" (lowercase).您使用"Label"键,而您需要使用"label" (小写)。

options=[
    {"label": "Last 12 months", "value": 12},
    {"label": "Last 6 months", "value": 6},
    {"label": "Last month", "value": 1}
]

should work.应该管用。

And you have to use value for "value" parameter, so:并且你必须使用 value 作为"value"参数,所以:

value=12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM