Hướng dẫn bootstrap 5 cheatsheet download - tải xuống trang phục bootstrap 5

Đây là một số nội dung giữ chỗ trong nội dung liên quan của tab nhà. Nhấp vào một tab khác sẽ chuyển đổi khả năng hiển thị của cái này cho lần tiếp theo. Tab JavaScript hoán đổi các lớp để kiểm soát khả năng hiển thị và kiểu dáng nội dung. Bạn có thể sử dụng nó với các tab, thuốc và bất kỳ điều hướng nào khác được hỗ trợ. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
1-powered navigation.

Đây là một số nội dung giữ chỗ của nội dung liên quan của tab Hồ sơ. Nhấp vào một tab khác sẽ chuyển đổi khả năng hiển thị của cái này cho lần tiếp theo. Tab JavaScript hoán đổi các lớp để kiểm soát khả năng hiển thị và kiểu dáng nội dung. Bạn có thể sử dụng nó với các tab, thuốc và bất kỳ điều hướng nào khác được hỗ trợ. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
1-powered navigation.

Đây là một số nội dung giữ chỗ của nội dung liên hệ của tab liên hệ. Nhấp vào một tab khác sẽ chuyển đổi khả năng hiển thị của cái này cho lần tiếp theo. Tab JavaScript hoán đổi các lớp để kiểm soát khả năng hiển thị và kiểu dáng nội dung. Bạn có thể sử dụng nó với các tab, thuốc và bất kỳ điều hướng nào khác được hỗ trợ. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
1-powered navigation.

dash-bootstrap-cheatsheet

Tương tác tiện dụng tiện dụng này giúp bạn dễ dàng sử dụng các lớp Bootstrap 5 với ứng dụng Dash của bạn được thực hiện với phiên bản mới nhất của Dash-Bootstrap Components v1.0

Nội phân Chính showShow

  • dash-bootstrap-cheatsheet
  • Xem nó trực tiếp tại https://dashcheatsheet.pythonanywhere.com/
  • Lưu ý - Đây là một WIP. Nếu bạn có bất kỳ nhận xét hoặc đề xuất hoặc chỉ muốn đưa ra một số ❤ Vui lòng mở một vấn đề.
  • Đồ thị trong các tab
  • Bắt đầu nhanh chóng
  • Thư viện thành phần mở rộng
  • Có thể tùy chỉnh cao
  • Xin chào Dash
  • Thực hiện thay đổi đầu tiên của bạn
  • Thêm về các thành phần HTML
  • Xin chào Dash
  • Thực hiện thay đổi đầu tiên của bạn
  • Thêm về các thành phần HTML
  • Các thành phần có thể tái sử dụng
  • Thêm về trực quan

Dash và Markdown

Lưu ý - Đây là một WIP. Nếu bạn có bất kỳ nhận xét hoặc đề xuất hoặc chỉ muốn đưa ra một số ❤ Vui lòng mở một vấn đề.

Thành phần cốt lõi

Xem nó trực tiếp tại https://dashcheatsheet.pythonanywhere.com/

Tiểu sử

Nếu bạn đang nâng cấp từ

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
4 V0.13 (sử dụng Bootstrap 4), bạn sẽ tìm thấy rất nhiều tính năng mới thú vị - nhưng cũng có một số thay đổi phá vỡ. Điều này chủ yếu là do Bootstrap 5 là một bản viết lại chính của dự án Bootstrap. Không chỉ có những thay đổi đối với một số thành phần, mà còn có nhiều lớp tiện ích mới và đổi tên.

  • Một ví dụ là Bootstrap 5 hiện đang hỗ trợ RTL, vì vậy các lớp được đổi tên thành các khởi động và kết thúc, thay vì các bên trái và bên phải. Điều này có nghĩa là cách mới để đặt lề trái hoặc bên phải là ClassName = "MS-2 ME-4" thay vì ClassName = "ML-2 MR-4". Ngoài ra còn có nhiều thứ mới như các lớp Opacity và các lớp giúp dễ dàng tạo ra các thành phần như: Hình ảnh
  • Để biết thêm thông tin, xem
  • import dash
    import dash_bootstrap_components as dbc
    
    app = dash.Dash(
        external_stylesheets=[dbc.themes.BOOTSTRAP]
    )
    
    app.layout = dbc.Alert(
        "Hello, Bootstrap!", className="m-5"
    )
    
    if __name__ == "__main__":
        app.run_server()
    4 thông báo V1

Hướng dẫn di chuyển bootstrap



import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
4 Hướng dẫn di cư

Tôi hy vọng chiếc Cheating này giúp bạn dễ dàng sử dụng DBC V1 và Bootstrap 5 trong ứng dụng Dash của bạn.

  • Đồ thị trong các tab
  • Trang này chứa các ứng dụng ví dụ được xây dựng với các thành phần bootstrap. Kiểm tra trang GitHub của chúng tôi để biết thêm.
  • Bắt đầu nhanh chóng
  • Thư viện thành phần mở rộng
  • Có thể tùy chỉnh cao
  • Xin chào Dash
  • Thực hiện thay đổi đầu tiên của bạn
  • Thêm về các thành phần HTML
  • Xin chào Dash
  • Thực hiện thay đổi đầu tiên của bạn
  • Thêm về các thành phần HTML
  • Các thành phần có thể tái sử dụng
  • Thêm về trực quan

Dash và Markdown

Thành phần cốt lõi

Đồ thị trong các tab

Xem nó trực tiếp tại https://dashcheatsheet.pythonanywhere.com/

Tiểu sử


Bắt đầu nhanh chóng

Nếu bạn đang nâng cấp từ

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
4 V0.13 (sử dụng Bootstrap 4), bạn sẽ tìm thấy rất nhiều tính năng mới thú vị - nhưng cũng có một số thay đổi phá vỡ. Điều này chủ yếu là do Bootstrap 5 là một bản viết lại chính của dự án Bootstrap. Không chỉ có những thay đổi đối với một số thành phần, mà còn có nhiều lớp tiện ích mới và đổi tên.

Một ví dụ là Bootstrap 5 hiện đang hỗ trợ RTL, vì vậy các lớp được đổi tên thành các khởi động và kết thúc, thay vì các bên trái và bên phải. Điều này có nghĩa là cách mới để đặt lề trái hoặc bên phải là ClassName = "MS-2 ME-4" thay vì ClassName = "ML-2 MR-4". Ngoài ra còn có nhiều thứ mới như các lớp Opacity và các lớp giúp dễ dàng tạo ra các thành phần như: Hình ảnh

Để biết thêm thông tin, xem

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
4 thông báo V1

pip install dash-bootstrap-components
import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()

Thư viện thành phần mở rộng

Hướng dẫn di chuyển bootstrap

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
4 Hướng dẫn di cư

Tôi hy vọng chiếc Cheating này giúp bạn dễ dàng sử dụng DBC V1 và Bootstrap 5 trong ứng dụng Dash của bạn.

Trang này chứa các ứng dụng ví dụ được xây dựng với các thành phần bootstrap. Kiểm tra trang GitHub của chúng tôi để biết thêm.


Có thể tùy chỉnh cao

Nội phân chính

Thanh bên đơn giản

Iris

Tương tác phân cụm bộ dữ liệu IRIS. Dựa trên ví dụ RSHiny này.

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

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

Xin chào Dash

Thực hiện thay đổi đầu tiên của bạn

$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)

Thêm về các thành phần HTML
in your web browser. You should see an app that looks like the one above.

Note:

  1. Các thành phần có thể tái sử dụng
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, html, dcc
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for your data.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    2
    and
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, html, dcc
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for your data.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    3.
  2. Thêm về trực quan

    Dash và Markdown
    The

    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, html, dcc
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for your data.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    5
    component generates a
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, html, dcc
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for your data.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    6 HTML element in your application.
    3. Not all components are pure HTML.
    The Dash Core Components module (
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, html, dcc
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for your data.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    7)
    contains higher-level components that are interactive and are generated with
    JavaScript, HTML, and CSS through the React.js library.

  3. Thành phần cốt lõi
    Dash is declarative: you will primarily describe your application
    through these attributes.

  4. Xem nó trực tiếp tại https://dashcheatsheet.pythonanywhere.com/
  5. Tiểu sử
    This application is using a custom CSS stylesheet and Dash Enterprise Design Kit
    to modify the default styles of the elements. You can learn more about custom CSS in the
    CSS tutorial.

Thực hiện thay đổi đầu tiên của bạn

Thêm về các thành phần HTML
you run your app with

$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
1.
This means that Dash
will automatically refresh your browser when you make a change in your code.

Các thành phần có thể tái sử dụng

$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
2 or the
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
3 data. Your app should auto-refresh with your change.

Bạn có thích tải nóng không? Bạn có thể tắt nó với ____34. Tìm hiểu thêm trong câu hỏi tài liệu công cụ Dash Dev? Xem Diễn đàn Cộng đồng Thảo luận tải lại nóng.
Learn more in Dash Dev Tools documentation
Questions? See the community forum hot reloading discussion.

Thêm về các thành phần HTML

Các thành phần HTML Dash (

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
4) chứa một lớp thành phần cho mọi thẻ HTML cũng như các đối số từ khóa cho tất cả các đối số HTML.
contains a component class for every HTML tag as well as keyword arguments for all of the HTML arguments.

Hãy để tùy chỉnh văn bản trong ứng dụng của chúng tôi bằng cách sửa đổi các kiểu nội tuyến của các thành phần. Tạo một tệp có tên

$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 với mã sau:
Create a file named
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 with the following code:

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd

app = Dash(__name__)

colors = {
    'background': '#111111',
    'text': '#7FDBFF'
}

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

fig.update_layout(
    plot_bgcolor=colors['background'],
    paper_bgcolor=colors['background'],
    font_color=colors['text']
)

app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
    html.H1(
        children='Hello Dash',
        style={
            'textAlign': 'center',
            'color': colors['text']
        }
    ),

    html.Div(children='Dash: A web application framework for your data.', style={
        'textAlign': 'center',
        'color': colors['text']
    }),

    dcc.Graph(
        id='example-graph-2',
        figure=fig
    )
])

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

Xin chào Dash

Dash: Một khung ứng dụng web cho dữ liệu của bạn.

Trong ví dụ này, chúng tôi đã sửa đổi các kiểu nội tuyến của

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
2 và
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
8Components với thuộc tính
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
9.
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
2
and
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
8components with the
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
9 property.

html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})

Mã trên được hiển thị trong ứng dụng Dash là

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
6.
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

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

Có một vài sự khác biệt quan trọng giữa các thuộc tính

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
4 và HTML:
and the HTML attributes:

  1. Thuộc tính
    $ python app.py
    ...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
    
    9 trong HTML là một chuỗi được phân tách bằng dấu chấm phẩy. Trong Dash, bạn chỉ có thể cung cấp một từ điển.
    you can just supply a dictionary.
  2. Các chìa khóa trong từ điển
    $ python app.py
    ...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
    
    9 được mô tả. Vì vậy, thay vì
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, dcc, html
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    colors = {
        'background': '#111111',
        'text': '#7FDBFF'
    }
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    fig.update_layout(
        plot_bgcolor=colors['background'],
        paper_bgcolor=colors['background'],
        font_color=colors['text']
    )
    
    app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
        html.H1(
            children='Hello Dash',
            style={
                'textAlign': 'center',
                'color': colors['text']
            }
        ),
    
        html.Div(children='Dash: A web application framework for your data.', style={
            'textAlign': 'center',
            'color': colors['text']
        }),
    
        dcc.Graph(
            id='example-graph-2',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    4, nó
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, dcc, html
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    colors = {
        'background': '#111111',
        'text': '#7FDBFF'
    }
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    fig.update_layout(
        plot_bgcolor=colors['background'],
        paper_bgcolor=colors['background'],
        font_color=colors['text']
    )
    
    app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
        html.H1(
            children='Hello Dash',
            style={
                'textAlign': 'center',
                'color': colors['text']
            }
        ),
    
        html.Div(children='Dash: A web application framework for your data.', style={
            'textAlign': 'center',
            'color': colors['text']
        }),
    
        dcc.Graph(
            id='example-graph-2',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    5.
    So, instead of
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, dcc, html
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    colors = {
        'background': '#111111',
        'text': '#7FDBFF'
    }
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    fig.update_layout(
        plot_bgcolor=colors['background'],
        paper_bgcolor=colors['background'],
        font_color=colors['text']
    )
    
    app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
        html.H1(
            children='Hello Dash',
            style={
                'textAlign': 'center',
                'color': colors['text']
            }
        ),
    
        html.Div(children='Dash: A web application framework for your data.', style={
            'textAlign': 'center',
            'color': colors['text']
        }),
    
        dcc.Graph(
            id='example-graph-2',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    4, it’s
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, dcc, html
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    colors = {
        'background': '#111111',
        'text': '#7FDBFF'
    }
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    fig.update_layout(
        plot_bgcolor=colors['background'],
        paper_bgcolor=colors['background'],
        font_color=colors['text']
    )
    
    app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
        html.H1(
            children='Hello Dash',
            style={
                'textAlign': 'center',
                'color': colors['text']
            }
        ),
    
        html.Div(children='Dash: A web application framework for your data.', style={
            'textAlign': 'center',
            'color': colors['text']
        }),
    
        dcc.Graph(
            id='example-graph-2',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    5.
  3. Thuộc tính HTML
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, dcc, html
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    colors = {
        'background': '#111111',
        'text': '#7FDBFF'
    }
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    fig.update_layout(
        plot_bgcolor=colors['background'],
        paper_bgcolor=colors['background'],
        font_color=colors['text']
    )
    
    app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
        html.H1(
            children='Hello Dash',
            style={
                'textAlign': 'center',
                'color': colors['text']
            }
        ),
    
        html.Div(children='Dash: A web application framework for your data.', style={
            'textAlign': 'center',
            'color': colors['text']
        }),
    
        dcc.Graph(
            id='example-graph-2',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    6 là
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, dcc, html
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    colors = {
        'background': '#111111',
        'text': '#7FDBFF'
    }
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    fig.update_layout(
        plot_bgcolor=colors['background'],
        paper_bgcolor=colors['background'],
        font_color=colors['text']
    )
    
    app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
        html.H1(
            children='Hello Dash',
            style={
                'textAlign': 'center',
                'color': colors['text']
            }
        ),
    
        html.Div(children='Dash: A web application framework for your data.', style={
            'textAlign': 'center',
            'color': colors['text']
        }),
    
        dcc.Graph(
            id='example-graph-2',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    7 trong dấu gạch ngang.
  4. Trẻ em của thẻ HTML được chỉ định thông qua đối số từ khóa
    # Run this app with `python app.py` and
    # visit http://127.0.0.1:8050/ in your web browser.
    
    from dash import Dash, html, dcc
    import plotly.express as px
    import pandas as pd
    
    app = Dash(__name__)
    
    # assume you have a "long-form" data frame
    # see https://plotly.com/python/px-arguments/ for more options
    df = pd.DataFrame({
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })
    
    fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for your data.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure=fig
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    
    8. Theo quy ước, đây luôn là đối số đầu tiên và vì vậy nó thường bị bỏ qua.
    argument. By convention, this is always the first argument and so it is often omitted.

Bên cạnh đó, tất cả các thuộc tính và thẻ HTML có sẵn đều có sẵn cho bạn trong bối cảnh Python của bạn.
to you within your Python context.


Các thành phần có thể tái sử dụng

Bằng cách viết đánh dấu của chúng tôi trong Python, chúng tôi có thể tạo các thành phần có thể tái sử dụng phức tạp như các bảng mà không cần chuyển đổi ngữ cảnh hoặc ngôn ngữ.

Dưới đây, một ví dụ nhanh chóng tạo ra

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd

app = Dash(__name__)

colors = {
    'background': '#111111',
    'text': '#7FDBFF'
}

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

fig.update_layout(
    plot_bgcolor=colors['background'],
    paper_bgcolor=colors['background'],
    font_color=colors['text']
)

app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
    html.H1(
        children='Hello Dash',
        style={
            'textAlign': 'center',
            'color': colors['text']
        }
    ),

    html.Div(children='Dash: A web application framework for your data.', style={
        'textAlign': 'center',
        'color': colors['text']
    }),

    dcc.Graph(
        id='example-graph-2',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
9 từ khung dữ liệu gấu trúc. Tạo một tệp có tên
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 với mã sau:
Pandas dataframe. Create a file named
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 with the following code:

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html
import pandas as pd

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/c78bf172206ce24f77d6363a2d754b59/raw/c353e8ef842413cae56ae3920b8fd78468aa4cb2/usa-agricultural-exports-2011.csv')


def generate_table(dataframe, max_rows=10):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ])


app = Dash(__name__)

app.layout = html.Div([
    html.H4(children='US Agriculture Exports (2011)'),
    generate_table(df)
])

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

Xuất khẩu nông nghiệp Hoa Kỳ (2011)

Không tên: 0tiểu bangTổng xuất khẩuthịt bòthịt lợngia cầmsản phẩm bơ sữaTrái cây tươiTrái cây ProcTổng số trái câyrau tươiRau ProcTổng số rauNgôlúa mìbông
Alabama1390.63 34.4 10.6 481.0 4.06 8.0 17.1 25.11 5.5 8.9 14.33 34.9 70.0 317.61
1 Alaska13.31 0.2 0.1 0.19 0.6 1.0 1.56
2 Arizona1463.17 71.3 17.9 105.48 19.3 41.0 60.27 147.5 239.4 386.91 7.3 48.7 423.95
3 Arkansas3586.02 53.2 29.4 562.9 3.53 2.2 4.7 6.88 4.4 7.1 11.45 69.5 114.5 665.44
4 California16472.88 228.7 11.1 225.4 929.95 2791.8 5944.6 8736.4 803.2 1303.5 2106.79 34.6 249.3 1064.95
5 Colorado1851.33 261.4 66.0 14.0 71.94 5.7 12.2 17.99 45.1 73.2 118.27 183.2 400.5
6 Connecticut259.62 1.1 0.1 6.9 9.49 4.2 8.9 13.1 4.3 6.9 11.16
7 Del biết282.19 0.4 0.6 114.7 2.3 0.5 1.0 1.53 7.6 12.4 20.03 26.9 22.9
8 Florida3764.09 42.6 0.9 56.9 66.31 438.2 933.1 1371.36 171.9 279.0 450.86 3.5 1.8 78.24
9 Georgia2860.84 31.0 18.9 630.4 38.38 74.6 158.9 233.51 59.0 95.8 154.77 57.8 65.4 1154.07

Thêm về trực quan

Mô -đun thành phần lõi Dash (

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7) bao gồm một thành phần gọi là
html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
2.
module (
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7) includes a component called
html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
2.

html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
2 hiển thị trực quan hóa dữ liệu tương tác bằng cách sử dụng thư viện đồ thị JavaScript nguồn mở. Plotly.js hỗ trợ hơn 35 loại biểu đồ và hiển thị biểu đồ trong cả SVG chất lượng vector và WebGL hiệu suất cao.
renders interactive data visualizations using the open source
plotly.js JavaScript graphing
library. Plotly.js supports over 35 chart types and renders charts in
both vector-quality SVG and high-performance WebGL.

Đối số

html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
4 trong thành phần ____52 là đối số
html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
4 giống nhau được sử dụng bởi
html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
7, thư viện đồ thị Python nguồn mở Plotly. Kiểm tra tài liệu và thư viện Plotly.py để tìm hiểu thêm.
component is the same
html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
4 argument that is used by
html.H1('Hello Dash', style={'textAlign': 'center', 'color': '#7FDBFF'})
7, Plotly’s
open source Python graphing library.
Check out the plotly.py documentation and gallery
to learn more.

Dưới đây, một ví dụ tạo ra một âm mưu phân tán từ khung dữ liệu gấu trúc. Tạo một tệp có tên

$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 với mã sau:
Pandas dataframe. Create a file named
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 with the following code:

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd


app = Dash(__name__)

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/5d1ea79569ed194d432e56108a04d188/raw/a9f9e8076b837d541398e999dcbac2b2826a81f8/gdp-life-exp-2007.csv')

fig = px.scatter(df, x="gdp per capita", y="life expectancy",
                 size="population", color="continent", hover_name="country",
                 log_x=True, size_max=60)

app.layout = html.Div([
    dcc.Graph(
        id='life-exp-vs-gdp',
        figure=fig
    )
])

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

Các biểu đồ này là tương tác và phản hồi. Nhìn qua các điểm để xem các giá trị của chúng, nhấp vào các mục huyền thoại để chuyển đổi dấu vết, nhấp và kéo để phóng to, giữ Shift và nhấp và kéo đến Pan.
Hover over points to see their values,
click on legend items to toggle traces,
click and drag to zoom,
hold down shift, and click and drag to pan.

Đánh dấu

Mặc dù Dash phơi bày HTML thông qua các thành phần HTML DASH (

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
4), nhưng có thể tẻ nhạt khi viết bản sao của bạn bằng HTML. Để viết các khối văn bản, bạn có thể sử dụng thành phần
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html
import pandas as pd

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/c78bf172206ce24f77d6363a2d754b59/raw/c353e8ef842413cae56ae3920b8fd78468aa4cb2/usa-agricultural-exports-2011.csv')


def generate_table(dataframe, max_rows=10):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ])


app = Dash(__name__)

app.layout = html.Div([
    html.H4(children='US Agriculture Exports (2011)'),
    generate_table(df)
])

if __name__ == '__main__':
    app.run_server(debug=True)
0 trong các thành phần lõi Dash (
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7). Tạo một tệp có tên
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 với mã sau:
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html
import pandas as pd

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/c78bf172206ce24f77d6363a2d754b59/raw/c353e8ef842413cae56ae3920b8fd78468aa4cb2/usa-agricultural-exports-2011.csv')


def generate_table(dataframe, max_rows=10):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ])


app = Dash(__name__)

app.layout = html.Div([
    html.H4(children='US Agriculture Exports (2011)'),
    generate_table(df)
])

if __name__ == '__main__':
    app.run_server(debug=True)
0 component in
Dash Core Components (
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7). Create a file named
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 with the following code:

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc

app = Dash(__name__)

markdown_text = '''
### Dash and Markdown

Dash apps can be written in Markdown.
Dash uses the [CommonMark](http://commonmark.org/)
specification of Markdown.
Check out their [60 Second Markdown Tutorial](http://commonmark.org/help/)
if this is your first introduction to Markdown!
'''

app.layout = html.Div([
    dcc.Markdown(children=markdown_text)
])

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

Dash và Markdown

Ứng dụng Dash có thể được viết bằng Markdown. Dash sử dụng đặc tả Commonmark của Markdown. Kiểm tra hướng dẫn đánh dấu 60 giây của họ nếu đây là phần giới thiệu đầu tiên của bạn về Markdown!
Dash uses the CommonMark
specification of Markdown.
Check out their 60 Second Markdown Tutorial
if this is your first introduction to Markdown!

Thành phần cốt lõi

Các thành phần lõi Dash (

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7) bao gồm một tập hợp các thành phần cấp cao hơn như thả xuống, đồ thị, khối đánh dấu, v.v.
includes a set of higher-level components like dropdowns, graphs, markdown blocks, and more.

Giống như tất cả các thành phần Dash, chúng được mô tả hoàn toàn khai báo. Mỗi tùy chọn có thể định cấu hình đều có sẵn dưới dạng đối số từ khóa của thành phần.
Every option that is configurable is available as a keyword argument
of the component.

Chúng tôi sẽ thấy nhiều thành phần này trong suốt hướng dẫn. Bạn có thể xem tất cả các thành phần có sẵn trong bộ sưu tập các thành phần cốt lõi Dash.
You can view all of the available components in the
Dash Core Components Gallery.

Dưới đây là một vài thành phần có sẵn. Tạo một tệp có tên

$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 với mã sau:
Create a file named
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
6 with the following code:

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc

app = Dash(__name__)

app.layout = html.Div([
    html.Div(children=[
        html.Label('Dropdown'),
        dcc.Dropdown(['New York City', 'Montréal', 'San Francisco'], 'Montréal'),

        html.Br(),
        html.Label('Multi-Select Dropdown'),
        dcc.Dropdown(['New York City', 'Montréal', 'San Francisco'],
                     ['Montréal', 'San Francisco'],
                     multi=True),

        html.Br(),
        html.Label('Radio Items'),
        dcc.RadioItems(['New York City', 'Montréal', 'San Francisco'], 'Montréal'),
    ], style={'padding': 10, 'flex': 1}),

    html.Div(children=[
        html.Label('Checkboxes'),
        dcc.Checklist(['New York City', 'Montréal', 'San Francisco'],
                      ['Montréal', 'San Francisco']
        ),

        html.Br(),
        html.Label('Text Input'),
        dcc.Input(value='MTL', type='text'),

        html.Br(),
        html.Label('Slider'),
        dcc.Slider(
            min=0,
            max=9,
            marks={i: f'Label {i}' if i == 1 else str(i) for i in range(1, 6)},
            value=5,
        ),
    ], style={'padding': 10, 'flex': 1})
], style={'display': 'flex', 'flex-direction': 'row'})

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

Thả xuống

Thả xuống đa lựa chọn

Các mặt hàng radio

Hộp kiểm

Đầu vào văn bản

Thanh trượt

Cứu giúp

Các thành phần Dash được khai báo: Mọi khía cạnh có thể định cấu hình của các thành phần này được đặt trong quá trình khởi tạo làm đối số từ khóa.
components is set during instantiation as a keyword argument.

Gọi

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html
import pandas as pd

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/c78bf172206ce24f77d6363a2d754b59/raw/c353e8ef842413cae56ae3920b8fd78468aa4cb2/usa-agricultural-exports-2011.csv')


def generate_table(dataframe, max_rows=10):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ])


app = Dash(__name__)

app.layout = html.Div([
    html.H4(children='US Agriculture Exports (2011)'),
    generate_table(df)
])

if __name__ == '__main__':
    app.run_server(debug=True)
5 trong bảng điều khiển Python của bạn trên bất kỳ thành phần nào để tìm hiểu thêm về một thành phần và các đối số có sẵn của nó.
learn more about a component and its available arguments.

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)

app.layout = dbc.Alert(
    "Hello, Bootstrap!", className="m-5"
)

if __name__ == "__main__":
    app.run_server()
0

Bản tóm tắt

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
1 của ứng dụng Dash mô tả ứng dụng trông như thế nào.
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
1 là một cây các thành phần phân cấp.
The
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
1 is a hierarchical tree of components.

Các thành phần HTML Dash (

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
4) cung cấp các lớp cho tất cả các thẻ HTML và các đối số từ khóa mô tả các thuộc tính HTML như
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
9,
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd

app = Dash(__name__)

colors = {
    'background': '#111111',
    'text': '#7FDBFF'
}

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

fig.update_layout(
    plot_bgcolor=colors['background'],
    paper_bgcolor=colors['background'],
    font_color=colors['text']
)

app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
    html.H1(
        children='Hello Dash',
        style={
            'textAlign': 'center',
            'color': colors['text']
        }
    ),

    html.Div(children='Dash: A web application framework for your data.', style={
        'textAlign': 'center',
        'color': colors['text']
    }),

    dcc.Graph(
        id='example-graph-2',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
6 và
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd


app = Dash(__name__)

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/5d1ea79569ed194d432e56108a04d188/raw/a9f9e8076b837d541398e999dcbac2b2826a81f8/gdp-life-exp-2007.csv')

fig = px.scatter(df, x="gdp per capita", y="life expectancy",
                 size="population", color="continent", hover_name="country",
                 log_x=True, size_max=60)

app.layout = html.Div([
    dcc.Graph(
        id='life-exp-vs-gdp',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
1.Các thành phần lõi Dash (
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7) tạo ra các thành phần cấp cao hơn như điều khiển và đồ thị.
tags and the keyword arguments describe the HTML attributes like
$ python app.py
...Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
9,
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd

app = Dash(__name__)

colors = {
    'background': '#111111',
    'text': '#7FDBFF'
}

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

fig.update_layout(
    plot_bgcolor=colors['background'],
    paper_bgcolor=colors['background'],
    font_color=colors['text']
)

app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
    html.H1(
        children='Hello Dash',
        style={
            'textAlign': 'center',
            'color': colors['text']
        }
    ),

    html.Div(children='Dash: A web application framework for your data.', style={
        'textAlign': 'center',
        'color': colors['text']
    }),

    dcc.Graph(
        id='example-graph-2',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
6, and
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, dcc, html
import plotly.express as px
import pandas as pd


app = Dash(__name__)

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/5d1ea79569ed194d432e56108a04d188/raw/a9f9e8076b837d541398e999dcbac2b2826a81f8/gdp-life-exp-2007.csv')

fig = px.scatter(df, x="gdp per capita", y="life expectancy",
                 size="population", color="continent", hover_name="country",
                 log_x=True, size_max=60)

app.layout = html.Div([
    dcc.Graph(
        id='life-exp-vs-gdp',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
1. Dash Core Components (
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)
7) generates higher-level components like controls and graphs.

Để tham khảo, xem:

  • Bộ sưu tập thành phần cốt lõi Dash
  • Bộ sưu tập linh kiện HTML Dash

Phần tiếp theo của hướng dẫn Dash bao gồm cách làm cho các ứng dụng này tương tác.Hướng dẫn Dash Phần 3: Gọi lại cơ bản
Dash Tutorial Part 3: Basic Callbacks