首页 > 解决方案 > 在 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 个下拉列表,其中第二个列表中的值取决于第一个下拉列表中选择的选项。

我希望它像所附图片一样,用户选择图表类型,然后显示相应的选项,用户可以在这些选项旁边输入一些内容

我想做什么

标签: python-3.xdashboardplotly-dash

解决方案


推荐阅读