|
4 | 4 | Dash实例 |
5 | 5 | """ |
6 | 6 |
|
7 | | -import datetime |
8 | 7 | import dash |
9 | | -import dash_core_components as dcc |
10 | | -import dash_html_components as html |
11 | | -import dash_bootstrap_components as dbc |
| 8 | +import datetime |
12 | 9 | from dash.dependencies import Output, Input, State |
13 | | -from Dash.config import * |
14 | | -from Dash.components import drop_down_list |
15 | | -from Dash.components import email_input, password_input, email_input_row, password_input_row |
16 | | -from Dash.components import radioitems, checklist, radioitems_inline, checklist_inline |
17 | | -from Dash.components import tab1_content, tab2_content |
18 | | -from Dash.components import generate_table |
| 10 | +from Dash.components import * |
19 | 11 |
|
20 | 12 |
|
21 | 13 | # 创建应用 |
|
25 | 17 | # 创建布局 |
26 | 18 | app.layout = html.Div(children=[ |
27 | 19 | # DIV布局 ======================================================================================== |
28 | | - dbc.Row(children=dbc.Col( |
29 | | - html.Div("单独的DIV", style={"backgroundColor": color_primary_light, "height": 100, "padding": 20, "margin": 5}) |
30 | | - )), |
| 20 | + dbc.Row(children=dbc.Col(html.Div("单独的DIV", style={"backgroundColor": color_primary_light, "height": 100, "padding": 10, "margin": 5}))), |
31 | 21 | dbc.Row(children=[ |
32 | | - dbc.Col(html.Div("One of three columns", style={"backgroundColor": color_info_light, "margin": 5})), |
33 | | - dbc.Col(html.Div("One of three columns", style={"backgroundColor": color_info_light, "margin": 5})), |
34 | | - dbc.Col(html.Div("One of three columns", style={"backgroundColor": color_info_light, "margin": 5})), |
| 22 | + dbc.Col(html.Div("One of three columns", style={"backgroundColor": color_info_light, "padding": 10, "margin": 5})), |
| 23 | + dbc.Col(html.Div("One of three columns", style={"backgroundColor": color_info_light, "padding": 10, "margin": 5})), |
| 24 | + dbc.Col(html.Div("One of three columns", style={"backgroundColor": color_info_light, "padding": 10, "margin": 5})), |
35 | 25 | ], no_gutters=True), |
36 | 26 |
|
37 | | - html.Div(children=[ |
38 | | - dbc.Row(dbc.Col(html.Div("A single, half-width column, width=6"), width=6), style={"backgroundColor": color_primary_light, "margin": 5}), |
39 | | - dbc.Row(dbc.Col(html.Div("An automatically sized column"), width="auto"), style={"backgroundColor": color_secondary_light, "margin": 5}), |
40 | | - dbc.Row([ |
41 | | - dbc.Col(html.Div("One of four columns"), width=3, style={"backgroundColor": color_danger_light}), |
42 | | - dbc.Col(html.Div("Two of four columns"), style={"backgroundColor": color_info_light}), |
43 | | - dbc.Col(html.Div("One of four columns"), width=3, style={"backgroundColor": color_warning_light}), |
44 | | - ], style={"margin": 5}), |
45 | | - ]), |
| 27 | + dbc.Row(children=dbc.Col(html.Div("A single, half-width column, width=6", style={"backgroundColor": color_primary_light, "margin": 5}), width=6)), |
| 28 | + dbc.Row(children=dbc.Col(html.Div("An automatically sized column", style={"backgroundColor": color_secondary_light, "margin": 5}), width="auto")), |
| 29 | + dbc.Row(children=[ |
| 30 | + dbc.Col(html.Div("One of 4 columns", style={"backgroundColor": color_info_light, "padding": 10, "margin": 5}), width=3), |
| 31 | + dbc.Col(html.Div("Two of 4 columns", style={"backgroundColor": color_info_light, "padding": 10, "margin": 5})), |
| 32 | + dbc.Col(html.Div("One of 4 columns", style={"backgroundColor": color_info_light, "padding": 10, "margin": 5}), width=3), |
| 33 | + ], no_gutters=True), |
46 | 34 |
|
47 | 35 | html.Br(), html.Br(), |
48 | 36 | # 显示文字 ======================================================================================== |
49 | 37 | html.Div(children=[ |
50 | 38 | html.H1(children="Hello Dash H1"), |
51 | 39 | html.H2(children="Hello Dash H2"), |
52 | 40 | html.H3(children="Hello Dash H3"), |
53 | | - html.H4(children="Hello Dash H4"), |
| 41 | + html.H4(children=["This is a heading with a badge! ", dbc.Badge("New!", color="success")]), |
54 | 42 | html.P(children=html.A(children="这是一个百度链接", href="http://baidu.com")), |
55 | 43 | html.Label(children="这是一个Lable"), |
56 | | - html.H4(["This is a heading with a badge! ", dbc.Badge("New!", color="success")]), |
57 | 44 | dcc.Markdown(children=markdown_text), |
58 | 45 | ], style={"margin": 5}), |
59 | 46 |
|
|
64 | 51 | dbc.Alert("info!", color="info"), |
65 | 52 | dbc.Alert("warning!", color="warning"), |
66 | 53 | dbc.Alert("danger!", color="danger"), |
| 54 | + # dbc.Alert("link!", color="link"), |
67 | 55 | ], style={"margin": 5}), |
68 | 56 |
|
69 | 57 | html.Br(), html.Br(), |
|
88 | 76 | dbc.CardText("and some text, and a footer!"), |
89 | 77 | ]), |
90 | 78 | dbc.CardFooter("Footer"), |
91 | | - ], outline=True, color="primary")), |
| 79 | + ], outline=True, color="danger")), |
92 | 80 | ]), style={"margin": 5}), |
93 | 81 |
|
94 | 82 | html.Br(), html.Br(), |
|
99 | 87 | dbc.Button("Secondary", color="secondary", className="mr-2"), |
100 | 88 | dbc.Button("Success", color="success", className="mr-3"), |
101 | 89 | dbc.Button("Info", color="info", className="mr-4"), |
102 | | - dbc.Button("Warning", color="warning", className="mr-5"), |
103 | | - dbc.Button("Danger", color="danger", className="mr-1"), |
| 90 | + dbc.Button("Warning", color="warning", className="mr-3"), |
| 91 | + dbc.Button("Danger", color="danger", className="mr-2"), |
| 92 | + dbc.Button("outline", outline=True), |
104 | 93 | ], style={"margin": 5}), |
105 | 94 |
|
106 | 95 | html.Div(children=[ |
|
119 | 108 | is_in=True, |
120 | 109 | appear=False, |
121 | 110 | ), |
122 | | - ], style={"margin": 5}), |
| 111 | + ], style={"margin": 5, "marginTop": 20}), |
123 | 112 |
|
124 | 113 | html.Div(children=[ |
125 | 114 | html.P(["Click on the word ", html.Span("popover", id="popover-target")]), |
|
143 | 132 | ], style={"margin": 5}), |
144 | 133 |
|
145 | 134 | html.Div(children=dcc.ConfirmDialogProvider( |
146 | | - dbc.Button("ConfirmDialogProvider", color="primary"), |
147 | 135 | id="confirm", |
| 136 | + children=dbc.Button("ConfirmDialogProvider", color="primary"), |
148 | 137 | message="Danger danger! Are you sure you want to continue?" |
149 | | - ), style={"margin": 5}), |
| 138 | + ), style={"margin": 5, "marginBottom": 20}), |
150 | 139 |
|
151 | 140 | html.Div(children=dbc.Row(children=[ |
152 | 141 | dbc.Col(dbc.DropdownMenu(label="Menu-md", bs_size="md", children=drop_down_list)), |
|
175 | 164 | dbc.Input(placeholder="A small input...", bs_size="sm", className="mb-3"), |
176 | 165 | dbc.Input(placeholder="Valid input...", valid=True, className="mb-3"), |
177 | 166 | dbc.Input(placeholder="Invalid input...", invalid=True, className="mb-3"), |
| 167 | + dbc.Input(value=10, type="number", className="mb-3"), |
178 | 168 | dcc.Textarea(placeholder="Enter a value...", style={"width": "50%"}), |
179 | 169 | ], style={"margin": 5}), |
180 | 170 |
|
|
204 | 194 |
|
205 | 195 | html.Br(), html.Br(), |
206 | 196 | # 表单类 ======================================================================================== |
207 | | - dbc.Form(children=[email_input, password_input], style={"margin": 20, "backgroundColor": color_secondary_light}), |
208 | | - dbc.Form(children=[email_input_row, password_input_row], style={"margin": 20, "backgroundColor": color_secondary_light}), |
| 197 | + dbc.Form(children=[email_input, password_input], style={"margin": 5, "backgroundColor": color_secondary_light}), |
| 198 | + dbc.Form(children=[email_input_row, password_input_row], style={"margin": 5, "backgroundColor": color_secondary_light}), |
209 | 199 | dbc.Form(children=[ |
210 | 200 | dbc.FormGroup([ |
211 | 201 | dbc.Label("Email", className="mr-2"), |
|
223 | 213 | dbc.Label("Date", className="mr-2"), |
224 | 214 | dcc.DatePickerRange(id="date-picker-range", start_date=datetime.datetime(1997, 5, 3), end_date_placeholder_text="Select!") |
225 | 215 | ], className="mr-3"), |
226 | | - ], inline=True, style={"margin": 20, "backgroundColor": color_secondary_light}), |
| 216 | + ], inline=True, style={"margin": 5, "backgroundColor": color_secondary_light}), |
227 | 217 |
|
228 | 218 | html.Br(), html.Br(), |
| 219 | + # 表单类 ======================================================================================== |
229 | 220 | html.Div(children=[ |
230 | 221 | dbc.Label("Slider", html_for="slider"), |
231 | 222 | dcc.Slider(min=0, max=9, marks={i: "Label {}".format(i) if i == 1 else str(i) for i in range(1, 6)}, value=5), |
|
235 | 226 | ], style={"margin": 5}), |
236 | 227 |
|
237 | 228 | html.Div(children=[ |
| 229 | + dbc.Label("Progress", html_for="progress"), |
238 | 230 | dbc.Progress(id="progress", value=0, striped=True, animated=True), |
239 | 231 | dcc.Interval(id="interval", interval=250, n_intervals=0), |
240 | 232 | ], style={"margin": 5}), |
241 | | - |
242 | 233 | html.Div(children=[radioitems, checklist, radioitems_inline, checklist_inline], style={"margin": 5}), |
243 | 234 |
|
244 | 235 | html.Br(), html.Br(), |
|
249 | 240 | dbc.ListGroupItem("External link", href="https://google.com"), |
250 | 241 | dbc.ListGroupItem("Disabled link", href="https://google.com", disabled=True), |
251 | 242 | dbc.ListGroupItem("Button", id="button-item", n_clicks=0, action=True), |
252 | | - ], style={"margin": 20}), |
| 243 | + ], style={"margin": 5}), |
253 | 244 |
|
254 | 245 | dbc.ListGroup(children=[ |
255 | 246 | dbc.ListGroupItem("The primary item", color="primary"), |
|
258 | 249 | dbc.ListGroupItem("A warning item", color="warning"), |
259 | 250 | dbc.ListGroupItem("A dangerous item", color="danger"), |
260 | 251 | dbc.ListGroupItem("An informative item", color="info"), |
261 | | - ], style={"margin": 20}), |
| 252 | + ], style={"margin": 5}), |
262 | 253 |
|
263 | 254 | dbc.ListGroup(children=[ |
264 | 255 | dbc.ListGroupItem([ |
|
269 | 260 | dbc.ListGroupItemHeading("This item also has a heading"), |
270 | 261 | dbc.ListGroupItemText("And some more text underneath too"), |
271 | 262 | ]), |
272 | | - ], style={"margin": 20}), |
| 263 | + ], style={"margin": 5}), |
273 | 264 |
|
274 | 265 | html.Br(), html.Br(), |
275 | 266 | # Tab实例 ======================================================================================== |
@@ -344,4 +335,4 @@ def switch_tab(at): |
344 | 335 |
|
345 | 336 |
|
346 | 337 | if __name__ == "__main__": |
347 | | - app.run_server(debug=True) |
| 338 | + app.run_server(host="0.0.0.0", debug=True) |
0 commit comments