nadijagr commited on
Commit
8e71a15
·
verified ·
1 Parent(s): 32416db

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +891 -0
app.py ADDED
@@ -0,0 +1,891 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Dash app with dbc components used for testing.
2
+
3
+ Thanks to https://github.com/AnnMarieW for providing the file.
4
+ """
5
+
6
+ import dash_bootstrap_components as dbc
7
+ import vizro
8
+ from dash import Dash, Input, Output, State, callback, clientside_callback, html
9
+
10
+ app = Dash(__name__, external_stylesheets=[vizro.bootstrap, dbc.icons.FONT_AWESOME])
11
+ DBC_DOCS = "https://www.dash-bootstrap-components.com/docs/components/"
12
+
13
+
14
+ def make_subheading(label, link):
15
+ """Creates a subheading with a link to the docs."""
16
+ slug = label.replace(" ", "")
17
+ heading = html.H3(
18
+ html.Span(
19
+ [
20
+ label,
21
+ html.A(
22
+ html.I(className="bi bi-book h4 ms-2"),
23
+ href=f"{DBC_DOCS}{link}",
24
+ target="_blank",
25
+ id=f"tooltip_target_{slug}",
26
+ ),
27
+ ],
28
+ ),
29
+ )
30
+
31
+ return html.Div(
32
+ [
33
+ heading,
34
+ dbc.Tooltip(f"See {label} documentation", target=f"tooltip_target_{slug}"),
35
+ ],
36
+ className="mt-3",
37
+ )
38
+
39
+
40
+ alerts1 = dbc.Col(
41
+ [
42
+ dbc.Alert("This is a primary alert", color="primary"),
43
+ dbc.Alert("This is a secondary alert", color="secondary"),
44
+ dbc.Alert("This is a success alert! Well done!", color="success"),
45
+ dbc.Alert("This is a warning alert... be careful...", color="warning"),
46
+ ],
47
+ md=6,
48
+ xs=12,
49
+ )
50
+ alerts2 = dbc.Col(
51
+ [
52
+ dbc.Alert("This is a danger alert. Scary!", color="danger"),
53
+ dbc.Alert("This is an info alert. Good to know!", color="info"),
54
+ dbc.Alert("This is a light alert", color="light"),
55
+ dbc.Alert("This is a dark alert", color="dark"),
56
+ ],
57
+ md=6,
58
+ xs=12,
59
+ )
60
+ alerts = html.Div(
61
+ [make_subheading("dbc.Alert", "alert"), dbc.Row([alerts1, alerts2])],
62
+ className="mb-4",
63
+ )
64
+
65
+
66
+ badge = html.Div(
67
+ [
68
+ dbc.Badge("Primary", color="primary", class_name="me-1"),
69
+ dbc.Badge("Secondary", color="secondary", class_name="me-1"),
70
+ dbc.Badge("Success", color="success", class_name="me-1"),
71
+ dbc.Badge("Warning", color="warning", class_name="me-1"),
72
+ dbc.Badge("Danger", color="danger", class_name="me-1"),
73
+ dbc.Badge("Info", color="info", class_name="me-1"),
74
+ dbc.Badge("Light", color="light", class_name="me-1"),
75
+ dbc.Badge("Dark", color="dark"),
76
+ ],
77
+ className="mb-2",
78
+ )
79
+
80
+ badge_pills = html.Div(
81
+ [
82
+ dbc.Badge("Primary", color="primary", class_name="me-1", pill=True),
83
+ dbc.Badge("Secondary", color="secondary", class_name="me-1", pill=True),
84
+ dbc.Badge("Success", color="success", class_name="me-1", pill=True),
85
+ dbc.Badge("Warning", color="warning", class_name="me-1", pill=True),
86
+ dbc.Badge("Danger", color="danger", class_name="me-1", pill=True),
87
+ dbc.Badge("Info", color="info", class_name="me-1", pill=True),
88
+ dbc.Badge("Light", color="light", class_name="me-1", pill=True),
89
+ dbc.Badge("Dark", color="dark", pill=True),
90
+ ],
91
+ )
92
+
93
+ badges = html.Div(
94
+ [make_subheading("dbc.Badge", "badge"), badge, badge_pills],
95
+ className="mb-4",
96
+ )
97
+
98
+ buttons1 = dbc.Col(
99
+ [
100
+ make_subheading("dbc.Button", "button"),
101
+ html.Div(
102
+ [
103
+ dbc.Button("Primary", color="primary", class_name="me-1 mt-1"),
104
+ dbc.Button("Secondary", color="secondary", class_name="me-1 mt-1"),
105
+ dbc.Button("Success", color="success", class_name="me-1 mt-1"),
106
+ dbc.Button("Warning", color="warning", class_name="me-1 mt-1"),
107
+ dbc.Button("Danger", color="danger", class_name="me-1 mt-1"),
108
+ dbc.Button("Info", color="info", class_name="me-1 mt-1"),
109
+ ],
110
+ className="mb-2",
111
+ ),
112
+ html.Div(
113
+ [
114
+ dbc.Button(
115
+ "Primary",
116
+ outline=True,
117
+ color="primary",
118
+ class_name="me-1 mt-1",
119
+ ),
120
+ dbc.Button(
121
+ "Secondary",
122
+ outline=True,
123
+ color="secondary",
124
+ class_name="me-1 mt-1",
125
+ ),
126
+ dbc.Button(
127
+ "Success",
128
+ outline=True,
129
+ color="success",
130
+ class_name="me-1 mt-1",
131
+ ),
132
+ dbc.Button(
133
+ "Warning",
134
+ outline=True,
135
+ color="warning",
136
+ class_name="me-1 mt-1",
137
+ ),
138
+ dbc.Button(
139
+ "Danger",
140
+ outline=True,
141
+ color="danger",
142
+ class_name="me-1 mt-1",
143
+ ),
144
+ dbc.Button("Info", outline=True, color="info", class_name="me-1 mt-1"),
145
+ ],
146
+ className="mb-2",
147
+ ),
148
+ html.Div(
149
+ [
150
+ dbc.Button("Regular", color="primary", class_name="me-1 mt-1"),
151
+ dbc.Button(
152
+ "Active",
153
+ color="primary",
154
+ active=True,
155
+ class_name="me-1 mt-1",
156
+ ),
157
+ dbc.Button(
158
+ "Disabled",
159
+ color="primary",
160
+ disabled=True,
161
+ class_name="me-1 mt-1",
162
+ ),
163
+ ],
164
+ className="mb-2",
165
+ ),
166
+ html.Div(
167
+ [
168
+ dbc.Button("Large button", size="lg", class_name="me-1 mt-1"),
169
+ dbc.Button("Regular button", class_name="me-1 mt-1"),
170
+ dbc.Button("Small button", size="sm", class_name="me-1 mt-1"),
171
+ ],
172
+ className="mb-2",
173
+ ),
174
+ ],
175
+ lg=6,
176
+ xs=12,
177
+ )
178
+
179
+ buttons2 = dbc.Col(
180
+ [
181
+ make_subheading("ButtonGroup", "buttongroups"),
182
+ html.Div(
183
+ dbc.ButtonGroup(
184
+ [
185
+ dbc.Button("Success", color="success"),
186
+ dbc.Button("Warning", color="warning"),
187
+ dbc.Button("Danger", color="danger"),
188
+ ]
189
+ ),
190
+ className="mb-2",
191
+ ),
192
+ html.Div(
193
+ dbc.ButtonGroup(
194
+ [
195
+ dbc.Button("First"),
196
+ dbc.Button("Second"),
197
+ dbc.DropdownMenu(
198
+ [
199
+ dbc.DropdownMenuItem("Item 1"),
200
+ dbc.DropdownMenuItem("Item 2"),
201
+ ],
202
+ label="Dropdown",
203
+ group=True,
204
+ ),
205
+ ],
206
+ vertical=True,
207
+ ),
208
+ className="mb-2",
209
+ ),
210
+ ],
211
+ lg=6,
212
+ xs=12,
213
+ )
214
+
215
+ buttons = dbc.Row([buttons1, buttons2], class_name="mb-4")
216
+
217
+ cards = html.Div(
218
+ [
219
+ make_subheading("dbc.Card", "card"),
220
+ dbc.Row(
221
+ [
222
+ dbc.Col(
223
+ dbc.Card(
224
+ [
225
+ dbc.CardHeader("Header"),
226
+ dbc.CardBody(
227
+ [
228
+ html.H5(
229
+ "This card has a title",
230
+ className="card-title",
231
+ ),
232
+ html.P("And some text", className="card-text"),
233
+ ]
234
+ ),
235
+ ]
236
+ )
237
+ ),
238
+ dbc.Col(
239
+ dbc.Card(
240
+ [
241
+ dbc.CardBody(
242
+ [
243
+ html.H5(
244
+ "This card has a title",
245
+ className="card-title",
246
+ ),
247
+ html.P(
248
+ "and some text, but no header",
249
+ className="card-text",
250
+ ),
251
+ ]
252
+ )
253
+ ],
254
+ outline=True,
255
+ color="primary",
256
+ )
257
+ ),
258
+ dbc.Col(
259
+ dbc.Card(
260
+ [
261
+ dbc.CardBody(
262
+ [
263
+ html.H5(
264
+ "This card has a title",
265
+ className="card-title",
266
+ ),
267
+ html.P(
268
+ "and some text, and a footer!",
269
+ className="card-text",
270
+ ),
271
+ ]
272
+ ),
273
+ dbc.CardFooter("Footer"),
274
+ ],
275
+ outline=True,
276
+ color="dark",
277
+ )
278
+ ),
279
+ ]
280
+ ),
281
+ ],
282
+ className="mb-4",
283
+ )
284
+
285
+ collapse = html.Div(
286
+ [
287
+ make_subheading("dbc.Collapse", "collapse"),
288
+ html.Div(
289
+ [
290
+ dbc.Button(
291
+ "Open collapse",
292
+ id="dbc-gallery-x-collapse-button",
293
+ class_name="mb-2",
294
+ ),
295
+ dbc.Collapse(
296
+ dbc.Card(dbc.CardBody("This content is hidden in the collapse")),
297
+ id="dbc-gallery-x-collapse",
298
+ ),
299
+ ]
300
+ ),
301
+ ],
302
+ className="mb-4",
303
+ )
304
+
305
+
306
+ @callback(
307
+ Output("dbc-gallery-x-collapse", "is_open"),
308
+ [Input("dbc-gallery-x-collapse-button", "n_clicks")],
309
+ [State("dbc-gallery-x-collapse", "is_open")],
310
+ )
311
+ def toggle_collapse(n, is_open):
312
+ """Make toggle collapse."""
313
+ if n:
314
+ return not is_open
315
+ return is_open
316
+
317
+
318
+ fade = html.Div(
319
+ [
320
+ make_subheading("dbc.Fade", "fade"),
321
+ html.Div(
322
+ [
323
+ dbc.Button(
324
+ "Toggle fade",
325
+ id="dbc-gallery-x-fade-button",
326
+ style={"marginBottom": "1rem"},
327
+ ),
328
+ dbc.Fade(
329
+ dbc.Card(
330
+ dbc.CardBody(
331
+ html.P(
332
+ "This content fades in and out",
333
+ className="card-text",
334
+ )
335
+ )
336
+ ),
337
+ id="dbc-gallery-x-fade",
338
+ is_in=True,
339
+ ),
340
+ ]
341
+ ),
342
+ ],
343
+ )
344
+
345
+
346
+ @callback(
347
+ Output("dbc-gallery-x-fade", "is_in"),
348
+ [Input("dbc-gallery-x-fade-button", "n_clicks")],
349
+ [State("dbc-gallery-x-fade", "is_in")],
350
+ )
351
+ def toggle_fade(n, is_in):
352
+ """Make toggle fade."""
353
+ if n:
354
+ return not is_in
355
+ return is_in
356
+
357
+
358
+ form = html.Div(
359
+ [
360
+ make_subheading("dbc.Form", "form"),
361
+ dbc.Form(
362
+ [
363
+ html.Div(
364
+ [
365
+ dbc.Label("Username"),
366
+ dbc.Input(
367
+ placeholder="Enter your username",
368
+ type="text",
369
+ ),
370
+ dbc.FormText(
371
+ [
372
+ "Can't remember your username? ",
373
+ html.A(
374
+ "Click here.",
375
+ href="#",
376
+ className="text-muted",
377
+ style={"textDecoration": "underline"},
378
+ ),
379
+ ]
380
+ ),
381
+ ]
382
+ ),
383
+ html.Div(
384
+ [
385
+ dbc.Label("Username"),
386
+ dbc.Input(
387
+ placeholder="Enter your password",
388
+ type="password",
389
+ ),
390
+ dbc.FormText(
391
+ [
392
+ "Can't remember your password? ",
393
+ html.A(
394
+ "Click here.",
395
+ href="#",
396
+ className="text-muted",
397
+ style={"textDecoration": "underline"},
398
+ ),
399
+ ]
400
+ ),
401
+ ]
402
+ ),
403
+ ]
404
+ ),
405
+ ],
406
+ className="mb-4",
407
+ )
408
+
409
+ input_ = html.Div(
410
+ [
411
+ make_subheading("dbc.Input", "input"),
412
+ html.Div(
413
+ [
414
+ dbc.Label("Valid text input"),
415
+ dbc.Input(type="text", valid=True),
416
+ dbc.FormFeedback("That's a valid input!", type="valid"),
417
+ ]
418
+ ),
419
+ html.Div(
420
+ [
421
+ dbc.Label("Invalid text input"),
422
+ dbc.Input(type="text", invalid=True),
423
+ dbc.FormFeedback("That's an invalid input...", type="invalid"),
424
+ ]
425
+ ),
426
+ ]
427
+ )
428
+
429
+ checklist_items = html.Div(
430
+ [
431
+ make_subheading("dbc.Checklist", "input"),
432
+ dbc.Row(
433
+ [
434
+ dbc.Col(
435
+ dbc.Checklist(
436
+ id="gallery_checklist1",
437
+ options=[
438
+ {
439
+ "label": f"Option {i}",
440
+ "value": i,
441
+ }
442
+ for i in range(3)
443
+ ],
444
+ value=[1, 2],
445
+ )
446
+ ),
447
+ dbc.Col(
448
+ dbc.Checklist(
449
+ id="gallery_checklist2",
450
+ options=[
451
+ {
452
+ "label": f"Option {i}",
453
+ "value": i,
454
+ }
455
+ for i in range(3)
456
+ ],
457
+ value=[1, 2],
458
+ switch=True,
459
+ )
460
+ ),
461
+ ]
462
+ ),
463
+ html.H5("Inline checklist", className="mt-3"),
464
+ dbc.Checklist(
465
+ id="gallery_checklist3",
466
+ options=[{"label": f"Option {i + 1}", "value": i} for i in range(5)],
467
+ value=[0, 4],
468
+ inline=True,
469
+ ),
470
+ ],
471
+ className="mb-4",
472
+ )
473
+
474
+ radio_items = html.Div(
475
+ [
476
+ make_subheading("dbc.RadioItems", "input"),
477
+ dbc.RadioItems(
478
+ id="gallery_radio1",
479
+ options=[{"label": f"Option {i + 1}", "value": i} for i in range(3)],
480
+ value=0,
481
+ ),
482
+ html.H5("Inline radioitems", className="mt-3"),
483
+ dbc.RadioItems(
484
+ id="gallery_radio2",
485
+ options=[{"label": f"Option {i + 1}", "value": i} for i in range(5)],
486
+ value=0,
487
+ inline=True,
488
+ ),
489
+ ]
490
+ )
491
+
492
+ input_group = html.Div(
493
+ [
494
+ make_subheading("InputGroup and addons", "input_group"),
495
+ dbc.InputGroup(
496
+ [
497
+ dbc.Button("To the left!", color="danger"),
498
+ dbc.Input(type="text"),
499
+ ],
500
+ class_name="my-3",
501
+ ),
502
+ dbc.InputGroup(
503
+ [
504
+ dbc.Input(type="text"),
505
+ dbc.Button("To the right!", color="success"),
506
+ ],
507
+ class_name="mb-3",
508
+ ),
509
+ dbc.InputGroup(
510
+ [
511
+ dbc.InputGroupText("@"),
512
+ dbc.Input(type="text", placeholder="Enter username"),
513
+ ],
514
+ class_name="mb-3",
515
+ ),
516
+ ],
517
+ className="mb-4",
518
+ )
519
+
520
+ list_group = html.Div(
521
+ [
522
+ make_subheading("dbc.ListGroup", "list_group"),
523
+ dbc.ListGroup(
524
+ [
525
+ dbc.ListGroupItem("Item 1", color="primary", action=True),
526
+ dbc.ListGroupItem("Item 2"),
527
+ dbc.ListGroupItem("Item 3"),
528
+ dbc.ListGroupItem(
529
+ [
530
+ html.H5("Item 4 heading"),
531
+ html.P("Item 4 text"),
532
+ ]
533
+ ),
534
+ ]
535
+ ),
536
+ ],
537
+ className="mb-4",
538
+ )
539
+
540
+
541
+ COOKIE = "https://todaysmama.com/.image/t_share/MTU5OTEwMzkyMDIyMTE1NzAz/cookie-monster.png"
542
+ modal = html.Div(
543
+ [
544
+ make_subheading("dbc.Modal", "modal"),
545
+ html.P(
546
+ [
547
+ dbc.Button("Show the cookie monster", id="dbc-gallery-x-button"),
548
+ dbc.Modal(
549
+ [
550
+ dbc.ModalHeader("Cookies!"),
551
+ dbc.ModalBody(html.Img(src=COOKIE, style={"width": "100%"})),
552
+ ],
553
+ id="dbc-gallery-x-modal",
554
+ is_open=False,
555
+ ),
556
+ ]
557
+ ),
558
+ ],
559
+ className="mb-4",
560
+ )
561
+
562
+
563
+ @callback(
564
+ Output("dbc-gallery-x-modal", "is_open"),
565
+ [Input("dbc-gallery-x-button", "n_clicks")],
566
+ [State("dbc-gallery-x-modal", "is_open")],
567
+ )
568
+ def toggle_modal(n, is_open):
569
+ """Enable modal to work."""
570
+ if n:
571
+ return not is_open
572
+ return is_open
573
+
574
+
575
+ DBC_HOME = "https://www.dash-bootstrap-components.com/"
576
+ DBC_GITHUB = "https://github.com/dbc-team/dash-bootstrap-components"
577
+
578
+ navbar_children = [
579
+ dbc.NavItem(dbc.NavLink("GitHub", href=DBC_GITHUB, target="_blank")),
580
+ dbc.DropdownMenu(
581
+ nav=True,
582
+ in_navbar=True,
583
+ label="Menu",
584
+ children=[
585
+ dbc.DropdownMenuItem("Entry 1", href="https://google.com"),
586
+ dbc.DropdownMenuItem("Entry 2", href="/test"),
587
+ dbc.DropdownMenuItem(divider=True),
588
+ dbc.DropdownMenuItem("A heading", header=True),
589
+ dbc.DropdownMenuItem(
590
+ "Entry 3",
591
+ href="/external-relative",
592
+ external_link=True,
593
+ ),
594
+ dbc.DropdownMenuItem("Entry 4 - does nothing"),
595
+ ],
596
+ ),
597
+ ]
598
+
599
+ navbar = html.Div(
600
+ [
601
+ make_subheading("dbc.Navbar", "navbar"),
602
+ dbc.NavbarSimple(
603
+ children=navbar_children,
604
+ brand="Navbar",
605
+ brand_href=DBC_HOME,
606
+ color="primary",
607
+ dark=True,
608
+ class_name="mb-3",
609
+ ),
610
+ dbc.NavbarSimple(
611
+ children=navbar_children,
612
+ brand="Navbar",
613
+ brand_href=DBC_HOME,
614
+ color="light",
615
+ class_name="mb-3",
616
+ ),
617
+ dbc.NavbarSimple(
618
+ children=navbar_children,
619
+ brand="Navbar",
620
+ brand_href=DBC_HOME,
621
+ color="dark",
622
+ dark=True,
623
+ ),
624
+ ],
625
+ className="mb-4",
626
+ )
627
+
628
+ popover = html.Div(
629
+ [
630
+ make_subheading("dbc.Popover", "popover"),
631
+ dbc.Button("Click to toggle popover", id="dbc-gallery-x-popover-target", color="danger"),
632
+ dbc.Popover(
633
+ [
634
+ dbc.PopoverHeader("Popover header"),
635
+ dbc.PopoverBody("Popover body"),
636
+ ],
637
+ id="dbc-gallery-x-popover",
638
+ is_open=False,
639
+ target="popover-target",
640
+ ),
641
+ ],
642
+ className="mb-4",
643
+ )
644
+
645
+
646
+ @callback(
647
+ Output("dbc-gallery-x-popover", "is_open"),
648
+ [Input("dbc-gallery-x-popover-target", "n_clicks")],
649
+ [State("dbc-gallery-x-popover", "is_open")],
650
+ )
651
+ def toggle_popover(n, is_open):
652
+ """Make popover reactive."""
653
+ if n:
654
+ return not is_open
655
+ return is_open
656
+
657
+
658
+ progress = html.Div(
659
+ [
660
+ make_subheading("dbc.Progress", "progress"),
661
+ dbc.Progress(value=25, label="25%"),
662
+ dbc.Progress(value=50, striped=True, className="my-2"),
663
+ dbc.Progress(value=75, color="success"),
664
+ ],
665
+ className="mb-4",
666
+ )
667
+
668
+ # ----- spinner
669
+
670
+ spinner = html.Div(
671
+ [
672
+ make_subheading("dbc.Spinner", "spinner"),
673
+ html.Div(
674
+ [
675
+ dbc.Spinner(color=col)
676
+ for col in [
677
+ "primary",
678
+ "secondary",
679
+ "success",
680
+ "warning",
681
+ "danger",
682
+ ]
683
+ ],
684
+ className="mb-2",
685
+ ),
686
+ html.Div(
687
+ [
688
+ dbc.Spinner(color=col, type="grow")
689
+ for col in [
690
+ "primary",
691
+ "secondary",
692
+ "success",
693
+ "warning",
694
+ "danger",
695
+ ]
696
+ ],
697
+ className="mb-2",
698
+ ),
699
+ ],
700
+ className="mb-4",
701
+ )
702
+
703
+ table = html.Div(
704
+ [
705
+ make_subheading("dbc.Table", "table"),
706
+ dbc.Table(
707
+ [
708
+ html.Thead(
709
+ html.Tr(
710
+ [
711
+ html.Th("#"),
712
+ html.Th("First name"),
713
+ html.Th("Last name"),
714
+ ]
715
+ )
716
+ ),
717
+ html.Tbody(
718
+ [
719
+ html.Tr(
720
+ [
721
+ html.Th("1", scope="row"),
722
+ html.Td("Tom"),
723
+ html.Td("Cruise"),
724
+ ]
725
+ ),
726
+ html.Tr(
727
+ [
728
+ html.Th("2", scope="row"),
729
+ html.Td("Jodie"),
730
+ html.Td("Foster"),
731
+ ]
732
+ ),
733
+ html.Tr(
734
+ [
735
+ html.Th("3", scope="row"),
736
+ html.Td("Chadwick"),
737
+ html.Td("Boseman"),
738
+ ]
739
+ ),
740
+ ]
741
+ ),
742
+ ],
743
+ responsive=True,
744
+ striped=True,
745
+ hover=True,
746
+ ),
747
+ ],
748
+ className="mb-4",
749
+ )
750
+
751
+ tabs = html.Div(
752
+ [
753
+ make_subheading("dbc.Tabs", "tabs"),
754
+ dbc.Tabs(
755
+ [
756
+ dbc.Tab(html.P("This is tab 1", className="py-3"), label="Tab 1"),
757
+ dbc.Tab(
758
+ dbc.Card(
759
+ [
760
+ html.P(
761
+ "This tab has a card!",
762
+ className="card-text",
763
+ ),
764
+ dbc.Button("Click here", color="success"),
765
+ ],
766
+ body=True,
767
+ ),
768
+ label="Tab 2",
769
+ style={"padding": "10px"},
770
+ ),
771
+ ]
772
+ ),
773
+ ],
774
+ className="mb-4",
775
+ )
776
+
777
+ toast = html.Div(
778
+ [
779
+ make_subheading("dbc.Toast", "toast"),
780
+ dbc.Button(
781
+ "Open toast",
782
+ id="dbc-gallery-x-auto-toast-toggle",
783
+ color="primary",
784
+ className="mb-3",
785
+ ),
786
+ dbc.Toast(
787
+ html.P("This is the content of the toast", className="mb-0"),
788
+ id="dbc-gallery-x-auto-toast",
789
+ header="This is the header",
790
+ icon="Primary",
791
+ duration=4000,
792
+ ),
793
+ ],
794
+ className="mb-2",
795
+ )
796
+
797
+
798
+ @callback(
799
+ Output("dbc-gallery-x-auto-toast", "is_open"),
800
+ [Input("dbc-gallery-x-auto-toast-toggle", "n_clicks")],
801
+ )
802
+ def open_toast(_):
803
+ """Make toast reactive."""
804
+ return True
805
+
806
+
807
+ tooltip = html.Div(
808
+ [
809
+ make_subheading("dbc.Tooltip", "tooltip"),
810
+ html.P(
811
+ [
812
+ "I wonder what ",
813
+ html.Span("floccinaucinihilipilification", id="gallery-tooltip-target"),
814
+ " means?",
815
+ ]
816
+ ),
817
+ dbc.Tooltip(
818
+ "Noun: rare, the action or habit of estimating something as worthless.",
819
+ target="gallery-tooltip-target",
820
+ ),
821
+ ],
822
+ className="mb-4",
823
+ )
824
+
825
+
826
+ layout = html.Div(
827
+ [
828
+ alerts,
829
+ badges,
830
+ buttons,
831
+ cards,
832
+ collapse,
833
+ fade,
834
+ dbc.Row(
835
+ [
836
+ dbc.Col([form, input_group], xs=12, md=6),
837
+ dbc.Col([input_], xs=12, md=6),
838
+ ]
839
+ ),
840
+ dbc.Row(
841
+ [
842
+ dbc.Col([checklist_items], xs=12, md=6),
843
+ dbc.Col([radio_items], xs=12, md=6),
844
+ ]
845
+ ),
846
+ list_group,
847
+ modal,
848
+ navbar,
849
+ popover,
850
+ progress,
851
+ spinner,
852
+ table,
853
+ tabs,
854
+ toast,
855
+ tooltip,
856
+ ],
857
+ className="dbc",
858
+ )
859
+
860
+ color_mode_switch = html.Span(
861
+ [
862
+ dbc.Label(class_name="fa fa-moon", html_for="color-mode-switch"),
863
+ dbc.Switch(id="color-mode-switch", value=False, class_name="d-inline-block ms-1", persistence=True),
864
+ dbc.Label(class_name="fa fa-sun", html_for="color-mode-switch"),
865
+ ]
866
+ )
867
+
868
+ app.layout = dbc.Container(
869
+ [
870
+ html.H3(["Bootstrap Light Dark Color Modes Demo"], className="bg-primary p-2"),
871
+ color_mode_switch,
872
+ layout,
873
+ ]
874
+ )
875
+
876
+
877
+ clientside_callback(
878
+ """
879
+ (switchOn) => {
880
+ document.documentElement.setAttribute('data-bs-theme', switchOn ? 'light' : 'dark');
881
+ return dash_clientside.no_update
882
+ }
883
+ """,
884
+ Output("color-mode-switch", "id"),
885
+ Input("color-mode-switch", "value"),
886
+ )
887
+
888
+
889
+ if __name__ == "__main__":
890
+ app.run(debug=True)
891
+