I am having some trouble to achieve the layout in the image below. What is left is for me is to add those 3 graphs that I included in blue.
So far, I have included everything in 1 row using up all 12 columns:
Col 1: with dropdowns and checklists → width=2 Col 2 → 12: all those cards/boxes on top. Now if I move to create a new row, I will get the graphs to be below the section on the left (so there will be this huge whitespace in the middle).
Col 1 can be bigger or smaller in size depending on the user choice. I want to make it independent, meaning no matter the size of it I want all the rest to be display like I have on the image here.
My simplified code:
JavaScript
x
179
179
1
layout = dbc.Container([
2
dbc.Row([
3
dbc.Col([
4
dbc.Card([
5
dbc.CardHeader('Portfolio Summary', style={'font-size': 20, 'textAlign': 'center', 'background-color': '#006398', 'color': 'white', 'font-weight': 'bold'}),
6
html.Label('Region:', style={'margin-left': '10px', 'font-size': 18, 'color': 'white', 'font-weight': 'bold'}),
7
dcc.RadioItems(id='region_radio',
8
options=[{'label': str(c), 'value': c} for c in sorted(df['Region'].unique())],
9
labelStyle={'display': 'block'},
10
inputStyle={'margin-right': '5px'},
11
style={'margin-left': '10px', 'margin-top': '0px', 'font-size': 15, 'color': 'white'}),
12
html.Label('Country:', style={'margin-left': '10px', 'font-size': 18, 'color': 'white', 'font-weight': 'bold'}),
13
dcc.Checklist(id='country_checklist', className='checkbox',
14
value=[],
15
labelStyle={'display': 'block'},
16
inputStyle={'margin-right': '5px'},
17
style={'margin-left': '10px', 'font-size': 15, 'color': 'white'}
18
),
19
html.Label('City:', style={'margin-left': '10px', 'font-size': 18, 'color': 'white', 'font-weight': 'bold'}),
20
dcc.Checklist(id='city_checklist', className='checkbox',
21
labelStyle={'display': 'block'},
22
inputStyle={'margin-right': '5px'},
23
style={'margin-left': '10px', 'font-size': 15, 'color': 'white'}
24
),
25
html.Label('Property Type:', style={'margin-left': '10px', 'font-size': 18, 'color': 'white', 'font-weight': 'bold'}),
26
dcc.Checklist(id='property_type_checklist', className='checkbox',
27
labelStyle={'display': 'block'},
28
inputStyle={'margin-right': '5px'},
29
options=[{'label': str(c), 'value': c} for c in sorted(df['Building Type'].unique())],
30
style={'margin-left': '10px', 'font-size': 15, 'color': 'white'}
31
),
32
html.Label('Ownership Type:', style={'margin-left': '10px', 'font-size': 18, 'color': 'white', 'font-weight': 'bold'}),
33
dcc.Checklist(id='ownership_type_checklist', className='checkbox',
34
labelStyle={'display': 'block'},
35
inputStyle={'margin-right': '5px'},
36
options=[{'label': str(c), 'value': c} for c in sorted(df['Ownership Type'].unique())],
37
style={'margin-left': '10px', 'font-size': 15, 'color': 'white'}
38
),
39
dbc.Button("Submit", id='submit_button', color="light", className="d-grid gap-2 col-6 mx-auto"),
40
dbc.Button("Clear All", color="dark", className="d-grid gap-2 col-6 mx-auto", href='/'),
41
], style={'margin-left': '-10px', 'background-color': '#006398'})
42
], width=2),
43
44
dbc.Col([
45
dbc.CardGroup([
46
dbc.Card(
47
dbc.CardBody([
48
html.H6('Countries', className='card-title'),
49
html.P(id='country_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
50
])
51
),
52
dbc.Card(
53
html.Div(className='fa fa-globe', style=card_icon),
54
className='bg-secondary',
55
style={'maxWidth': 55}
56
)], className='mt-4 shadow')
57
],style={'margin-top': '-23px'}, width=1),
58
59
dbc.Col([
60
dbc.CardGroup([
61
dbc.Card(
62
dbc.CardBody([
63
html.H6('Cities', className='card-title'),
64
html.P(id='city_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
65
])
66
),
67
dbc.Card(
68
html.Div(className='fa fa-city', style=card_icon),
69
className='bg-secondary',
70
style={'maxWidth': 55}
71
)], className='mt-4 shadow')
72
], style={'margin-top': '-23px'}, width=1),
73
74
dbc.Col([
75
dbc.CardGroup([
76
dbc.Card(
77
dbc.CardBody([
78
html.H6('Properties', className='card-title'),
79
html.P(id='property_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
80
])
81
),
82
dbc.Card(
83
html.Div(className='fa fa-building', style=card_icon),
84
className='bg-secondary',
85
style={'maxWidth': 55}
86
)], className='mt-4 shadow')
87
], style={'margin-top': '-23px'}, width=1),
88
89
dbc.Col([
90
dbc.CardGroup([
91
dbc.Card(
92
dbc.CardBody([
93
html.H6('Annual Rent', className='card-title'),
94
html.P(id='rent_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
95
])
96
),
97
dbc.Card(
98
html.Div(className='fa fa-coins', style=card_icon),
99
className='bg-secondary',
100
style={'maxWidth': 55}
101
)], className='mt-4 shadow')
102
], style={'margin-top': '-23px'}, width=2),
103
104
dbc.Col([
105
dbc.CardGroup([
106
dbc.Card(
107
dbc.CardBody([
108
html.H6('Total Area', className='card-title'),
109
html.P(id='area_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
110
])
111
),
112
dbc.Card(
113
html.Div(className='fa fa-expand', style=card_icon),
114
className='bg-secondary',
115
style={'maxWidth': 55}
116
)], className='mt-4 shadow')
117
], style={'margin-top': '-23px'}, width=1),
118
119
dbc.Col([
120
dbc.CardGroup([
121
dbc.Card(
122
dbc.CardBody([
123
html.H6('Rent/Area', className='card-title'),
124
html.P(id='rent_area_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
125
])
126
),
127
dbc.Card(
128
html.Div(className='fa fa-money-bill', style=card_icon),
129
className='bg-secondary',
130
style={'maxWidth': 55}
131
)], className='mt-4 shadow')
132
], style={'margin-top': '-23px'}, width=1),
133
134
dbc.Col([
135
dbc.CardGroup([
136
dbc.Card(
137
dbc.CardBody([
138
html.H6('Headcount', className='card-title'),
139
html.P(id='headcount_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
140
])
141
),
142
dbc.Card(
143
html.Div(className='fa fa-user', style=card_icon),
144
className='bg-secondary',
145
style={'maxWidth': 55}
146
)], className='mt-4 shadow')
147
], style={'margin-top': '-23px'}, width=1),
148
149
dbc.Col([
150
dbc.CardGroup([
151
dbc.Card(
152
dbc.CardBody([
153
html.H6('Deskcount', className='card-title'),
154
html.P(id='deskcount_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
155
])
156
),
157
dbc.Card(
158
html.Div(className='fa fa-couch', style=card_icon),
159
className='bg-secondary',
160
style={'maxWidth': 55}
161
)], className='mt-4 shadow')
162
], style={'margin-top': '-23px'}, width=1),
163
164
dbc.Col([
165
dbc.CardGroup([
166
dbc.Card(
167
dbc.CardBody([
168
html.H6('Cost/Person', className='card-title'),
169
html.P(id='cost_person_card', className='card-text', style={'font-size': 30, 'font-weight': 'bold', 'text-align': 'right'})
170
])
171
),
172
dbc.Card(
173
html.Div(className='fa fa-user-tag', style=card_icon),
174
className='bg-secondary',
175
style={'maxWidth': 55}
176
)], className='mt-4 shadow')
177
], style={'margin-top': '-23px'}, width=1),
178
]),
179
], fluid=True)
Advertisement
Answer
You can nest rows/cols to get the layout you’re requesting.
JavaScript
1
51
51
1
import dash
2
from dash import dcc, html
3
import dash_bootstrap_components as dbc
4
5
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
6
7
graph = dcc.Graph(figure={
8
'data': [
9
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
10
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
11
],
12
'layout': {
13
'title': 'Dash Data Visualization',
14
},
15
}, responsive=True, className="h-100")
16
17
app.layout = dbc.Container([
18
dbc.Row([
19
dbc.Col(html.Div("stuff", className="bg-secondary h-100"), width=2),
20
dbc.Col([
21
dbc.Row([
22
dbc.Col([html.Div("header", className="bg-primary")]),
23
dbc.Col([html.Div("header", className="bg-primary")]),
24
dbc.Col([html.Div("header", className="bg-primary")]),
25
dbc.Col([html.Div("header", className="bg-primary")], width=4)
26
]),
27
dbc.Row([
28
dbc.Col([graph]),
29
]),
30
dbc.Row([
31
dbc.Col([graph]),
32
]),
33
], width=5),
34
dbc.Col([
35
dbc.Row([
36
dbc.Col([html.Div("header", className="bg-primary")]),
37
dbc.Col([html.Div("header", className="bg-primary")]),
38
dbc.Col([html.Div("header", className="bg-primary")]),
39
dbc.Col([html.Div("header", className="bg-primary")]),
40
dbc.Col([html.Div("header", className="bg-primary")]),
41
]),
42
dbc.Row([
43
dbc.Col([graph]),
44
], className="h-100"),
45
], width=5),
46
])
47
], fluid=True)
48
49
app.run_server(debug=True)
50
51