首页 > 解决方案 > 如何使 Plotly Dash 日期选择器范围和按钮工作

问题描述

我正在使用DashbyPlotly创建仪表板,但这会将日期范围作为输入。但是我TypeError在尝试模仿此处显示的简单示例时遇到了麻烦。我不明白我在做什么错。下面是我的代码:

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

app = dash.Dash(__name__)

app.config['suppress_callback_exceptions'] = True
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True

app.layout = html.Div(children=[

    html.H1(children='AE Analytics Dashboard', style={'color': 'gray', 'text-align': 'center'}),
    html.Div(
        html.Div(
            dcc.Input(id='input-box', placeholder='Enter AE Name', type='text',value=''),
            dcc.DatePickerRange(
                id='date-picker-range',
                start_date_placeholder_text= 'Select a date!',
                end_date_placeholder_text='Select a date!'
            )
        ),
        html.Button('Submit', id='button'),
        # html.Div(id='output-container-button', children='Enter a value and press submit')
    )
])

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

错误:

TypeError:不可散列的类型:'DatePickerRange'

我在尝试使用时遇到以下错误html.Button

TypeError:传递给 Button 的格式字符串不受支持。格式

标签: python-3.xplotly

解决方案


我解决了。这是一个愚蠢的错误。以下是供任何人参考的更正代码。

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

app = dash.Dash(__name__)

app.config['suppress_callback_exceptions'] = True
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
app.layout = html.Div(children=[

    html.H1(children='AE Analytics Dashboard', style={'color': 'gray', 'text-align': 'center'}),
    html.Div(
        html.Div([
            dcc.Input(id='input-1-state', type='text', placeholder='AE Name', style={'text-align': 'center'}, value=''),
            dcc.DatePickerRange(
            id='date-picker-range',
            start_date_placeholder_text= 'Select a date!',
            end_date_placeholder_text='Select a date!'
        ),
            html.Button(id='submit-button', n_clicks=0, children='Submit')
            ]),
        ),
])

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

推荐阅读