我正在使用Dash
的{{1}}创建仪表板,但是它将“日期范围”作为输入。但是我在尝试模仿here中所示的简单示例时遇到了Plotly
。我不明白我在做什么错。下面是我的代码:
TypeError
错误:
TypeError:不可哈希类型:'DatePickerRange'
尝试使用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:不支持的格式字符串传递给Button。格式
答案 0 :(得分:1)
我解决了。这是一个愚蠢的错误。下面是更正后的代码,可供任何人参考。
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)