more dash workings
This commit is contained in:
+75
-11
@@ -1,21 +1,85 @@
|
||||
# Import packages
|
||||
from dash import Dash, html, dash_table
|
||||
import polars as pd
|
||||
import polars as pl
|
||||
import plotly.express as px
|
||||
from dash import Dash, html, dcc
|
||||
import dash_bootstrap_components as dbc
|
||||
from dash.dash_table import DataTable
|
||||
|
||||
# Incorporate data
|
||||
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')
|
||||
df = pl.read_parquet('data/warehouse/transactions.parquet')
|
||||
print("Data loaded from Parquet file:")
|
||||
print(df)
|
||||
|
||||
relevant_data = df.sql('''
|
||||
SELECT
|
||||
date,
|
||||
sum(transaction_amount) as total
|
||||
FROM self
|
||||
GROUP BY date
|
||||
ORDER BY date DESC
|
||||
'''
|
||||
)
|
||||
print("Data after SQL query:")
|
||||
print(relevant_data)
|
||||
|
||||
# Convert DataFrame to list of dictionaries
|
||||
data = df.to_pandas().to_dict('records')
|
||||
data = relevant_data.to_dicts()
|
||||
print("Data converted to list of dictionaries:")
|
||||
print(data)
|
||||
|
||||
# Initialize the app
|
||||
app = Dash()
|
||||
# Initialize the app with a dark theme
|
||||
app = Dash(external_stylesheets=[dbc.themes.DARKLY])
|
||||
|
||||
# Create the line graph with dark mode styling
|
||||
fig = px.line(relevant_data.to_pandas(), x="date", y="total", title='Spend Per Day')
|
||||
fig.update_layout(
|
||||
plot_bgcolor='black',
|
||||
paper_bgcolor='black',
|
||||
font_color='white'
|
||||
)
|
||||
|
||||
# App layout
|
||||
app.layout = [
|
||||
html.Div(children='My First App with Data'),
|
||||
dash_table.DataTable(data=data)
|
||||
]
|
||||
app.layout = dbc.Container(
|
||||
[
|
||||
dbc.Row(
|
||||
dbc.Col(html.Div("My First App with My Data", className="text-center text-light"), width=12)
|
||||
),
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Col(
|
||||
dbc.Card(
|
||||
dbc.CardBody(
|
||||
[
|
||||
html.H4("Data Table", className="card-title"),
|
||||
DataTable(
|
||||
data=data,
|
||||
columns=[{"name": i, "id": i} for i in relevant_data.columns],
|
||||
page_size=5,
|
||||
style_header={'backgroundColor': 'black', 'color': 'white'},
|
||||
style_cell={'backgroundColor': 'black', 'color': 'white'}
|
||||
)
|
||||
]
|
||||
),
|
||||
className="mb-4"
|
||||
),
|
||||
width=6
|
||||
),
|
||||
dbc.Col(
|
||||
dbc.Card(
|
||||
dbc.CardBody(
|
||||
[
|
||||
html.H4("Spend Per Day", className="card-title"),
|
||||
dcc.Graph(figure=fig)
|
||||
]
|
||||
),
|
||||
className="mb-4"
|
||||
),
|
||||
width=6
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
fluid=True
|
||||
)
|
||||
|
||||
# Run the app
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -2,4 +2,8 @@ python-dotenv
|
||||
polars
|
||||
requests
|
||||
pyyaml
|
||||
#visualisation requirements below
|
||||
dash
|
||||
pandas
|
||||
pyarrow
|
||||
dash-bootstrap-components
|
||||
Reference in New Issue
Block a user