added table
This commit is contained in:
BIN
src/components/.data_table.py.swp
Normal file
BIN
src/components/.data_table.py.swp
Normal file
Binary file not shown.
@ -18,14 +18,13 @@ def render(app: Dash, data: pd.DataFrame) -> html.Div:
|
||||
)
|
||||
def update_data_table(
|
||||
years: list[str], months: list[str], categories: list[str]
|
||||
) -> list[dict]:
|
||||
) -> html.Div:
|
||||
filtered_data = data.query(
|
||||
"year in @years and month in @months and category in @categories"
|
||||
)
|
||||
|
||||
if filtered_data.shape[0] == 0:
|
||||
return []
|
||||
|
||||
return html.Div("No data selected.", id=ids.DATA_TABLE)
|
||||
def create_pivot_table() -> pd.DataFrame:
|
||||
pt = filtered_data.pivot_table(
|
||||
values=DataSchema.AMOUNT,
|
||||
@ -36,16 +35,6 @@ def render(app: Dash, data: pd.DataFrame) -> html.Div:
|
||||
)
|
||||
return pt.reset_index().sort_values(DataSchema.AMOUNT, ascending=False)
|
||||
|
||||
return create_pivot_table().to_dict("records")
|
||||
return html.Div(dcc.Data_table(data=create_pivot_table(data), id=ids.DATA_TABLE)
|
||||
|
||||
return html.Div(
|
||||
DataTable(
|
||||
id=ids.DATA_TABLE,
|
||||
columns=[
|
||||
{"name": col, "id": col}
|
||||
for col in [DataSchema.CATEGORY, DataSchema.AMOUNT]
|
||||
],
|
||||
data=[],
|
||||
sort_action="native",
|
||||
)
|
||||
)
|
||||
return html.Div(id=ids.DATA_TABLE)
|
||||
|
Reference in New Issue
Block a user