Skip to content

Commit 93cde95

Browse files
committed
Move the controls to a sidebar
1 parent eb8650b commit 93cde95

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

apps/dash/3_update_table.py

+38-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

77
import logging
@@ -19,18 +19,43 @@
1919

2020
df = get_countries(html=False)
2121

22-
22+
# Create the layout with sidebar
2323
app.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

apps/dash/assets/style.css

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
margin: 0;
4+
padding: 0;
5+
background-color: #f5f5f5;
6+
}
7+
.container {
8+
display: flex;
9+
min-height: 100vh;
10+
}
11+
.sidebar {
12+
width: 250px;
13+
background-color: #f0f0f0;
14+
padding: 20px;
15+
box-shadow: 2px 0 5px rgba(0,0,0,0.1);
16+
}
17+
.main-content {
18+
flex: 1;
19+
padding: 20px;
20+
}

0 commit comments

Comments
 (0)