簡體   English   中英

標簽未顯示在 Dash Dropdown 中

[英]Labels not displaying in Dash Dropdown

我有兩個單獨的 Dash 下拉列表,我正在嘗試創建第二個(當我運行應用程序時,id= 'select_range' 不顯示選項標簽。

我收到的錯誤:

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'}
                    ))

])

您使用"Label"鍵,而您需要使用"label" (小寫)。

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

應該管用。

並且你必須使用 value 作為"value"參數,所以:

value=12

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM