python-3.x - 如何使 Plotly Dash 日期选择器范围和按钮工作
问题描述
我正在使用Dash
byPlotly
创建仪表板,但这会将日期范围作为输入。但是我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 的格式字符串不受支持。格式
解决方案
我解决了。这是一个愚蠢的错误。以下是供任何人参考的更正代码。
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)
推荐阅读
- amazon-web-services - 刷新 EC2 实例标签失败:SharedCredsLoad
- julia - 如何为正在开发的 Julia 项目下载和设置依赖项?
- laravel - Laravel 与 Litespeed 和 Apache2 和 ProxyPass 在登录后给出 403
- azure - 如何按用户分组并在 U-SQL 中创建具有值的列?
- jquery - 如何将 jquery 变量导出为 html 文件
- python - 将键值对存储为列表理解
- angular - 无法检索数组值
- php - 如何在 mysql 中创建表并更新后元表,例如 sku 行、价格、库存
- contextmenu - 如何完全禁用页面上的拼写检查?
- arrays - 将 x 添加到所有嵌套数组中的每个第二个元素的更快方法