-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
109 lines (76 loc) · 2.36 KB
/
streamlit_app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# ---------------------------------------- #
# IMPORTS #
# ---------------------------------------- #
# interface
import streamlit as st
# data manipulation
import pandas as pd
# data vis
import matplotlib.pyplot as plt
import plotly
import plotly.express as px
# project files
from source.main_chart import *
from source.map import *
from source.line import *
from source.sccatter import *
from source.utils import *
# ---------------------------------------- #
# GLOBAL VARIABLES #
# ---------------------------------------- #
# load files
df = pd.read_pickle('data/df_happiness.pkl')
df['regional_indicator'].replace(to_replace=[None], value = 'Other', inplace = True)
# copy the df to another variable
df_aux = df
def change_df(df_changed):
global df_aux
df_aux = df_changed
selected_countries = ['Brazil', 'Argentina',
'Greece', 'Germany',
'Finland', 'Denmark', 'Switzerland',
'Afghanistan', 'Zimbabwe', 'Rwanda']
# ---------------------------------------- #
# PAGE SETTINGS #
# ---------------------------------------- #
title = 'World Happiness Report Data Vis'
# Page settings
st.set_page_config(
page_title = title,
# layout = 'wide',
initial_sidebar_state = 'auto'
)
# Add the title
st.title(title)
# ---------------------------------------- #
# SIDE BAR #
# ---------------------------------------- #
# Title
st.sidebar.title('Filter the data:')
# Country multiselector
selected_countries = st.sidebar.multiselect(
label = 'Countries:',
options = df.country.unique(),
default = selected_countries
)
if len(selected_countries):
change_df(df[df.country.isin(selected_countries)])
else:
change_df(df)
# Checkbox for sorting
sort = st.sidebar.checkbox(
'Ascending order of happiness',
value = True)
# Column selector
selected_col = st.sidebar.selectbox(
'Select the X column to the Scatter',
options = df.columns[3:-2]
)
# ---------------------------------------- #
# PAGE ELEMENTS #
# ---------------------------------------- #
scatter = render_scatter(df_aux, st, sort)
line_chart = render_line(df_aux, st)
scatter2 = render_scatter_2(df_aux, selected_col, st)
map_chart = render_map(df, st)
st.dataframe(df.head())