mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-25 00:02:34 +02:00
Viz: Company stats (#64)
First connection to Postgres database and creating dashboard with dropdown and table --------- Co-authored-by: Tim <tim.ronneburg@outlook.de> Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de> Co-authored-by: Sebastian <94404394+SeZett@users.noreply.github.com>
This commit is contained in:
parent
82979b1981
commit
ba30ba2cc5
@ -1,9 +1,8 @@
|
|||||||
"""Dash."""
|
"""Dash."""
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from dash import Dash, dash_table
|
from dash import Dash, Input, Output, callback, dash_table, dcc, html
|
||||||
|
|
||||||
# from ..utils.postgres.connector import get_engine, init_db
|
|
||||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||||
from aki_prj23_transparenzregister.utils.postgres.connector import (
|
from aki_prj23_transparenzregister.utils.postgres.connector import (
|
||||||
get_session,
|
get_session,
|
||||||
@ -16,9 +15,29 @@ if __name__ == "__main__":
|
|||||||
companies_df: pd.DataFrame = pd.read_sql(str(query), session.bind) # type: ignore
|
companies_df: pd.DataFrame = pd.read_sql(str(query), session.bind) # type: ignore
|
||||||
app = Dash(__name__)
|
app = Dash(__name__)
|
||||||
|
|
||||||
app.layout = dash_table.DataTable(
|
app.layout = html.Div(
|
||||||
companies_df.to_dict("records"),
|
[
|
||||||
[{"name": i, "id": i} for i in companies_df.columns],
|
html.H1(children="Company Data", style={"textAlign": "center"}),
|
||||||
|
html.Div(
|
||||||
|
[
|
||||||
|
dcc.Dropdown(
|
||||||
|
companies_df.company_name.unique(),
|
||||||
|
"Firma 1",
|
||||||
|
id="dropdown-selection",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
html.Div(id="data_table"),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@callback(Output("data_table", "children"), Input("dropdown-selection", "value"))
|
||||||
|
def display_table(value: str) -> dash_table:
|
||||||
|
"""Output table with company stats based on dropdown value."""
|
||||||
|
dff = companies_df[companies_df.company_name == value]
|
||||||
|
return dash_table.DataTable(
|
||||||
|
data=dff.to_dict("records"),
|
||||||
|
columns=[{"id": c, "name": c} for c in companies_df.columns],
|
||||||
|
)
|
||||||
|
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user