Hello everyone!
Create 1 dashboard from 3 datasets with the same columns, each dataset must have an interactive table and 2/3 different interactive charts and 3 dropdowns
I have the following 3 csv files
tab_investments = https://projectgoodwilllink.s3.eu-south-1.amazonaws.com/Tab_macro(inv).csv
tab_passivity = https://projectgoodwilllink.s3.eu-south-1.amazonaws.com/Tab_macro(lai).csv
tab_macro = https://projectgoodwilllink.s3.eu-south-1.amazonaws.com/Tab_macro.csv
all three tables have the following columns:
Reporting country,Reference period,Item code,Item name,Value,Undertaking type
Example of the first 3 rows:
AUSTRIA,2016 Q3,R0030,Intangible assets,0,Life undertakings
AUSTRIA,2016 Q3,R0030,Intangible assets,0,Non-Life undertakings
AUSTRIA,2016 Q3,R0030,Intangible assets,0,Other undertakings
I need to create a dashboard that analyses and compares all three datasets
I thought of creating a dashboard divided into separate tabs and for each tab show the dataset in the form of an interactive table, under each table generate 3 interactive charts such as a pie chart taking the sum of Value divided by Country.
ideas for the other 1/2 charts?
How can I implement 4 dropdowns ( Reporting country,Reference period,Item name and Undertaking) acting on the charts, for each tab of the dashboard and thus for each dataframe?
the code I have been able to write so far:
import pandas as pd
import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import dash_bootstrap_components as dbc
# Carica i dati dai file csv
df_macro = pd.read_csv("C://Users/gianz/Desktop/Project_Work/Dataset_def/Dash Excel/Tab_macro.csv")
df_lai = pd.read_csv("C://Users/gianz/Desktop/Project_Work/Dataset_def/Dash Excel/Tab_macro(lai).csv")
df_inv = pd.read_csv("C://Users/gianz/Desktop/Project_Work/Dataset_def/Dash Excel/Tab_macro(inv).csv")
# Crea l'app Dash
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.title="PROJECT GOODWILL"
server = app.server # dashtools per il deploy
# Imposta il layout dell'app
app.layout = html.Div([
# Titolo dell'app
html.H1("Dashboard assicurativa Europa"),
# Tabs per le tre tabelle
dcc.Tabs(id="tabs", children=[
# Tab per la prima tabella
dcc.Tab(label="Tab_macro", children=[
# Dropdowns
html.Label('Reference period'),
dcc.Dropdown(
id='macro-reference-period',
options=[{'label': i, 'value': i} for i in df_macro['Reference period'].unique()],
value=df_macro['Reference period'].unique()[0]
),
html.Label('Item name'),
dcc.Dropdown(
id='macro-item-name',
options=[{'label': i, 'value': i} for i in df_macro['Item name'].unique()],
value=df_macro['Item name'].unique()[0]
),
html.Label('Undertaking type'),
dcc.Dropdown(
id='macro-undertaking-type',
options=[{'label': i, 'value': i} for i in df_macro['Undertaking type'].unique()],
value=df_macro['Undertaking type'].unique()[0]
),
# Tabella
dash_table.DataTable(
id='table_macro',
columns=[{"name": i, "id": i} for i in df_macro.columns],
data=df_macro.to_dict('records'),
page_size=25
),
# Grafici
html.Div([
dcc.Graph(
id='graph_macro_pie',
figure=px.pie(
df_macro,
names='Reporting country',
values='Somma di Value',
title='Somma di Value per Reporting country'
)
)
]),
html.Div([
dcc.Graph(
id='graph_macro_bar',
figure=px.bar(
df_macro,
x='Reporting country',
y='Somma di Value',
text='Reporting country',
title='Somma di Value per Reporting country'
)
)
]),
html.Div([
dcc.Graph(
id='graph_macro_line',
figure=px.line(
df_macro,
x='Reporting country',
y='Somma di Value',
text='Reporting country',
title='Somma di Value per Reporting country'
)
)
])
]),
# Tab per la seconda tabella
dcc.Tab(label="Tab_macro(inv)", children=[
# Dropdowns
html.Label('Reference period'),
dcc.Dropdown(
id='inv-reference-period',
options=[{'label': i, 'value': i} for i in df_inv['Reference period'].unique()],
value=df_inv['Reference period'].unique()[0]
),
html.Label('Item name'),
dcc.Dropdown(
id='inv-item-name',
options=[{'label': i, 'value': i} for i in df_inv['Item name'].unique()],
value=df_inv['Item name'].unique()[0]
),
html.Label('Undertaking type'),
dcc.Dropdown(
id='inv-undertaking-type',
options=[{'label': i, 'value': i} for i in df_inv['Undertaking type'].unique()],
value=df_inv['Undertaking type'].unique()[0]
),
# Tabella
dash_table.DataTable(
id='table_inv',
columns=[{"name": i, "id": i} for i in df_inv.columns],
data=df_inv.to_dict('records'),
page_size=25
),
# Grafici
html.Div([
dcc.Graph(
id='graph_inv_pie',
figure=px.pie(
df_inv,
names='Reporting country',
values='Somma di Value',
title='Somma di Value per Reporting country'
)
)
]),
html.Div([
dcc.Graph(
id='graph_inv_bar',
figure=px.bar(
df_inv,
x='Reporting country',
y='Somma di Value',
text='Reporting country',
title='Somma di Value per Reporting country'
)
)
]),
html.Div([
dcc.Graph(
id='graph_inv_line',
figure=px.line(
df_inv,
x='Reporting country',
y='Somma di Value',
text='Reporting country',
title='Somma di Value per Reporting country'
)
)
])
]),
# Tab per la terza tabella
dcc.Tab(label="Tab_macro(lai)", children=[
# Dropdowns
html.Label('Reference period'),
dcc.Dropdown(
id='lai-reference-period',
options=[{'label': i, 'value': i} for i in df_lai['Reference period'].unique()],
value=df_lai['Reference period'].unique()[0]
),
html.Label('Item name'),
dcc.Dropdown(
id='lai-item-name',
options=[{'label': i, 'value': i} for i in df_lai['Item name'].unique()],
value=df_lai['Item name'].unique()[0]
),
html.Label('Undertaking type'),
dcc.Dropdown(
id='lai-undertaking-type',
options=[{'label': i, 'value': i} for i in df_lai['Undertaking type'].unique()],
value=df_lai['Undertaking type'].unique()[0]
),
# Tabella
dash_table.DataTable(
id='table_lai',
columns=[{"name": i, "id": i} for i in df_lai.columns],
data=df_lai.to_dict('records'),
page_size=25
),
# Grafici
html.Div([
dcc.Graph(
id='graph_lai_pie',
figure=px.pie(
df_lai,
names='Reporting country',
values='Somma di Value',
title='Somma di Value per Reporting country'
)
)
]),
html.Div([
dcc.Graph(
id='graph_lai_bar',
figure=px.bar(
df_lai,
x='Reporting country',
y='Somma di Value',
text='Reporting country',
title='Somma di Value per Reporting country'
)
)
]),
html.Div([
dcc.Graph(
id='graph_lai_line',
figure=px.line(
df_lai,
x='Reporting country',
y='Somma di Value',
text='Reporting country',
title='Somma di Value per Reporting country'
)
)
])
]),
]),
])
@app.callback(
[dash.dependencies.Output("graph_macro_line", "figure"),
dash.dependencies.Output("graph_inv_line", "figure"),
dash.dependencies.Output("graph_lai_line", "figure")],
[dash.dependencies.Input("macro-reference-period", "value"),
dash.dependencies.Input("macro-item-name", "value"),
dash.dependencies.Input("macro-undertaking-type", "value"),
dash.dependencies.Input("inv-reference-period", "value"),
dash.dependencies.Input("inv-item-name", "value"),
dash.dependencies.Input("inv-undertaking-type", "value"),
dash.dependencies.Input("lai-reference-period", "value"),
dash.dependencies.Input("lai-item-name", "value"),
dash.dependencies.Input("lai-undertaking-type", "value")])
if __name__ == '__main__':
app.run_server(debug=True)
is that right?
How do I implement callbacks and functions to update charts based on dropdowns?
Many thanks to all