1
1
"""
2
- This is an example Dash application that uses the ITable component .
2
+ This is an example Dash application in which we update the table .
3
3
4
- Launch the app by running `python app .py`.
4
+ Launch the app by running `python 3_update_table .py`.
5
5
"""
6
6
7
7
import logging
19
19
20
20
df = get_countries (html = False )
21
21
22
-
22
+ # Create the layout with sidebar
23
23
app .layout = html .Div (
24
24
[
25
- html .H1 ("DataTable in a Dash application" ),
26
- dcc .Checklist (
27
- ["Select" , "Buttons" , "HTML" ],
28
- ["Select" ],
29
- id = "checklist" ,
30
- ),
31
- dcc .Input (id = "caption" , value = "table caption" ),
32
- ITable (id = "my_dataframe" , df = df ),
33
- html .Div (id = "output" ),
25
+ html .Div (
26
+ className = "container" ,
27
+ children = [
28
+ # Sidebar
29
+ html .Div (
30
+ className = "sidebar" ,
31
+ children = [
32
+ html .H2 ("Controls" ),
33
+ html .Label ("Table Options:" ),
34
+ dcc .Checklist (
35
+ ["Select" , "Buttons" , "HTML" ],
36
+ ["Select" ],
37
+ id = "checklist" ,
38
+ style = {"marginBottom" : "20px" },
39
+ ),
40
+ html .Label ("Table Caption:" ),
41
+ dcc .Input (
42
+ id = "caption" ,
43
+ value = "table caption" ,
44
+ style = {"width" : "100%" , "marginBottom" : "20px" },
45
+ ),
46
+ ],
47
+ ),
48
+ # Main content
49
+ html .Div (
50
+ className = "main-content" ,
51
+ children = [
52
+ html .H1 ("ITable in a Dash application" ),
53
+ ITable (id = "my_dataframe" ),
54
+ html .Div (id = "output" , style = {"marginTop" : "20px" }),
55
+ ],
56
+ ),
57
+ ],
58
+ )
34
59
]
35
60
)
36
61
@@ -51,7 +76,7 @@ def update_table(checklist, caption, selected_rows, dt_args):
51
76
kwargs = {}
52
77
53
78
# When df=None and when the dt_args don't change, the table is not updated
54
- if callback_context .triggered_id == "checklist" :
79
+ if callback_context .triggered_id in { None , "checklist" } :
55
80
kwargs ["df" ] = get_countries (html = "HTML" in checklist )
56
81
57
82
kwargs ["select" ] = "Select" in checklist
0 commit comments