如何做破折号下拉例如数据集

2024-05-09 01:43:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试用破折号绘制三个示例数据集,并希望使用下拉列表,以便一次只显示一个。 但是,它同时显示所有三个数据集,并且选择另一个下拉项不会更改图形

有人能帮忙吗? 我是新来的破折号,找不到一个简单的例子,这种情况下

# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']


app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'NYC'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': 'MTL'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': 'SF'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    ),

    html.Label('Dropdown'),
    dcc.Dropdown(
        options=[
            {'label': 'New York City', 'value': 'NYC'},
            {'label': u'Montréal', 'value': 'MTL'},
            {'label': 'San Francisco', 'value': 'SF'}
        ],
        value='MTL'
    )

])


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

Tags: nameimportappvaluehtmltypebarlabel