Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 724481f

Browse files
committed
🙈 forgot file
1 parent 8bbcb1c commit 724481f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/dash/utils.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import dash_html_components as html
2+
3+
4+
def merge(*args):
5+
merged = {}
6+
for arg in args:
7+
for key in arg:
8+
merged[key] = arg[key]
9+
return merged
10+
11+
12+
def section_title(title):
13+
return html.H4(title, style={"marginTop": "20px"})
14+
15+
16+
def html_table(
17+
df,
18+
base_column_style={},
19+
table_style={},
20+
column_style={},
21+
cell_style={},
22+
cell_style_by_column={},
23+
):
24+
header = []
25+
for column in df.columns:
26+
header.append(
27+
html.Th(
28+
column,
29+
style=merge(
30+
base_column_style,
31+
cell_style,
32+
column_style.get(column, {}),
33+
cell_style_by_column.get(column, {}),
34+
),
35+
)
36+
)
37+
38+
rows = []
39+
for i in range(len(df)):
40+
row = []
41+
for column in df.columns:
42+
row.append(
43+
html.Td(
44+
df.iloc[i][column],
45+
style=merge(cell_style, cell_style_by_column.get(column, {})),
46+
)
47+
)
48+
rows.append(html.Tr(row))
49+
50+
return html.Table(
51+
[html.Thead(header), html.Tbody(rows)],
52+
style=merge(table_style, {"marginTop": "20px", "marginBottom": "20px"}),
53+
)

0 commit comments

Comments
 (0)