Skip to content

Commit 5cbad1c

Browse files
author
xianhu
committed
update dbc-navbar
1 parent 12acfd4 commit 5cbad1c

4 files changed

Lines changed: 77 additions & 14 deletions

File tree

‎Dash/advcom/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# _*_ coding: utf-8 _*_
2+
3+
"""
4+
高级组件
5+
"""

‎Dash/advcom/navbar.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# _*_ coding: utf-8 _*_
2+
3+
"""
4+
导航栏
5+
"""
6+
7+
import dash_html_components as html
8+
import dash_bootstrap_components as dbc
9+
PLOTLY_LOGO = "https://images.plot.ly/logo/new-branding/plotly-logomark.png"
10+
11+
# 通用组件
12+
nav_item1 = dbc.NavItem(children=dbc.NavLink("首页", href="/"))
13+
nav_item2 = dbc.NavItem(children=dbc.NavLink("Link2", href="#"))
14+
drop_down = dbc.DropdownMenu(children=[
15+
dbc.DropdownMenuItem("More", header=True),
16+
dbc.DropdownMenuItem("Entry app1", href="/app1"),
17+
dbc.DropdownMenuItem("Entry app2", href="/app2"),
18+
dbc.DropdownMenuItem(divider=True),
19+
dbc.DropdownMenuItem("Entry app3", href="/app3"),
20+
dbc.DropdownMenuItem("Entry app4", href="/app4"),
21+
], nav=True, in_navbar=True, label="Menu")
22+
23+
# 定义不同的导航栏
24+
navbar_default = dbc.NavbarSimple(children=[nav_item1, nav_item2, drop_down], brand="Dash", brand_href="#", sticky="top")
25+
26+
navbar_custom = dbc.Navbar(children=dbc.Container(children=[
27+
dbc.NavbarBrand("Dash", href="#"),
28+
# dbc.NavbarToggler(id="navbar-toggler1"),
29+
dbc.Collapse(children=dbc.Nav([nav_item1, nav_item2, drop_down], className="ml-auto", navbar=True), navbar=True),
30+
]))
31+
32+
navbar_logo = dbc.Navbar(children=dbc.Container(children=[
33+
html.A(dbc.Row(children=[
34+
dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")),
35+
dbc.Col(dbc.NavbarBrand("Dash", className="ml-2")),
36+
], align="center", no_gutters=True), href="https://plot.ly"),
37+
# dbc.NavbarToggler(id="navbar-toggler2"),
38+
dbc.Collapse(children=dbc.Nav([nav_item1, nav_item2, drop_down], className="ml-auto", navbar=True), navbar=True),
39+
]), color="dark", dark=True)
40+
41+
navbar_search = dbc.Navbar(children=dbc.Container(children=[
42+
dbc.NavbarBrand("Search", href="#"),
43+
# dbc.NavbarToggler(id="navbar-toggler3"),
44+
dbc.Collapse(children=dbc.Row(children=[
45+
dbc.Col(dbc.Input(type="search", placeholder="Search")),
46+
# set width of button column to auto to allow search box to take up remaining space.
47+
dbc.Col(dbc.Button("Search", color="primary", className="ml-2"), width="auto"),
48+
], align="center", no_gutters=True, className="ml-auto flex-nowrap"), navbar=True),
49+
# keep button and search box on same row (flex-nowrap).
50+
# align everything on the right with left margin (ml-auto).
51+
]))

‎Dash/apps/app3.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
"name": "Trace 2",
3434
"mode": "markers",
3535
"marker": {"size": 12}
36-
}]
37-
}
36+
}],
37+
"layout": {
38+
"title": "Dash Data Visualization"
39+
},
40+
},
3841
),
3942

4043
html.Div(children=dbc.Row(children=[

‎Dash/index.py‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from Dash.app import app
1313
from Dash.apps import app1, app2, app3, app4
14-
14+
from Dash.advcom.navbar import nav_item1, nav_item2, drop_down, PLOTLY_LOGO
1515

1616
# 创建布局
1717
app.layout = html.Div([
@@ -23,16 +23,20 @@
2323
dcc.Store(id="session", storage_type="session"),
2424

2525
dcc.Location(id="url", refresh=False),
26-
dbc.Navbar(children=[
27-
dbc.NavItem(dbc.NavLink("Link", href="#")),
28-
dbc.DropdownMenu(children=[
29-
dbc.DropdownMenuItem("Entry 1"),
30-
dbc.DropdownMenuItem("Entry 2"),
31-
dbc.DropdownMenuItem(divider=True),
32-
dbc.DropdownMenuItem("Entry 3")
33-
], nav=True, in_navbar=True, label="Menu"),
34-
], brand="Demo", brand_href="/", sticky="top", color="light"),
35-
html.Div(id="page-content")
26+
27+
# 定义一个较为复杂的导航栏
28+
dbc.Navbar(children=dbc.Container(children=[
29+
html.A(dbc.Row(children=[
30+
dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")),
31+
dbc.Col(dbc.NavbarBrand("DashDemo", className="ml-2")),
32+
], align="center", no_gutters=True), href="https://plot.ly"),
33+
dbc.Collapse(children=dbc.Nav([nav_item1, nav_item2, drop_down], navbar=True), navbar=True),
34+
dbc.Collapse(children=dbc.Row(children=[
35+
dbc.Col(dbc.Input(type="search", placeholder="Search")),
36+
dbc.Col(dbc.Button("Search", color="primary", className="ml-2"), width="auto"),
37+
], align="center", no_gutters=True, className="ml-auto flex-nowrap"), navbar=True),
38+
]), color="light", light=True),
39+
html.Div(id="page-content"),
3640
])
3741

3842

@@ -46,7 +50,7 @@ def display_page(pathname):
4650
html.Br(),
4751
dcc.Link("Navigate to '/app2',组件相关", href="/app2"),
4852
html.Br(),
49-
dcc.Link("Navigate to '/app3',画图", href="/app3"),
53+
dcc.Link("Navigate to '/app3',画图相关", href="/app3"),
5054
html.Br(),
5155
dcc.Link("Navigate to '/app4',dash-table", href="/app4"),
5256
])

0 commit comments

Comments
 (0)