python-3.x - 在 Dash 中创建菜单
问题描述
我想用破折号制作一个动态菜单。我只是不确定如何去创建这个。
这就是我设法做到的:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
all_options = {
'Waterfall': {'query','Configuration'},
'Line Chart': {'query', 'period', 'date_from', 'date_to', 'previous_year_aggregation', 'current_year_aggregation',
'multi_year_stat_aggregation'}
}
app.layout = html.Div([
dcc.Dropdown(
id='chart_type',
options=[{'label': k, 'value': k} for k in all_options.keys()],
value='Waterfall'
),
html.Hr(),
dcc.Dropdown(id='chart_options'),
html.Hr(),
html.Div(id='display-selected-values')
])
@app.callback(
Output('chart_options', 'options'),
Input('chart_type', 'value'))
def set_chart_options(selected_chart):
return [{'label': i, 'value': i} for i in all_options[selected_chart]]
@app.callback(
Output('chart_options', 'value'),
Input('chart_options', 'options'))
def set_chart_options_value(available_options):
return available_options[0]['value']
@app.callback(
Output('display-selected-values', 'children'),
Input('chart_type', 'value'),
Input('chart_options', 'value'))
def set_display_children(selected_chart, selected_option):
return u'Chart:{} Option:{}'.format(
selected_chart, selected_option,
)
if __name__ == '__main__':
app.run_server(debug=True)
我可以制作 2 个下拉列表,其中第二个列表中的值取决于第一个下拉列表中选择的选项。
我希望它像所附图片一样,用户选择图表类型,然后显示相应的选项,用户可以在这些选项旁边输入一些内容
解决方案
推荐阅读
- javascript - 是否可以将 wordpress 时间保存到 jquery/javsacript 变量中?
- angular - 无法解析任何东西的所有参数:
- java - 当我关闭会话时,Spring Boot 关闭
- java - 如何在单独的行中显示错误消息
- java - 如何在aspectj中将一些参数从之前的方法传递到之后
- apache-spark - 错误:无法找到或加载主类 org.apache.spark.launcher.Main
- javascript - 使用 JS 从字符串中拆分 URL
- javascript - 如何通过开关条件访问数组?
- ios - 使用编码协议解析 JSON nil 值
- linux - 使用 .NET Core 在 Linux 上更改文件所有者