-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatting.py
43 lines (37 loc) · 919 Bytes
/
formatting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import dash
from dash import dash_table, dcc, html,Input, Output
import pandas as pd
app = dash.Dash(__name__)
# Initial data
data = [
{'a': 0.123, 'b': 'Text1'},
{'a': 0.456, 'b': 'Text2'},
{'a': 0.789, 'b': 'Text3'}
]
# Define the DataTable layout
app.layout = html.Div([
html.H3('??'),
dash_table.DataTable(
id='table',
columns=[
{'id': 'a', 'name': 'Custom Numeric'},
{'id': 'b', 'name': 'Custom String'}
],
data=data
)
])
# Callback to format the data
@app.callback(
Output('table', 'data'),
[Input('table', 'data')]
)
def format_data(rows):
print(rows)
# Iterate over rows to format the numeric column 'a'
for row in rows:
if isinstance(row['a'], (int, float)):
row['a'] = f"{row['a'] * 100:.2f}%"
print(rows)
return rows
if __name__ == '__main__':
app.run_server(debug=True)