11"""
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 .
33
4- Launch the app by running `python app .py`.
4+ Launch the app by running `python 3_update_table .py`.
55"""
66
77import logging
1919
2020df = get_countries (html = False )
2121
22-
22+ # Create the layout with sidebar
2323app .layout = html .Div (
2424 [
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+ )
3459 ]
3560)
3661
@@ -51,7 +76,7 @@ def update_table(checklist, caption, selected_rows, dt_args):
5176 kwargs = {}
5277
5378 # 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" } :
5580 kwargs ["df" ] = get_countries (html = "HTML" in checklist )
5681
5782 kwargs ["select" ] = "Select" in checklist
0 commit comments