Added World Map and organized app.py
Browse files
app.py
CHANGED
|
@@ -9,43 +9,78 @@
|
|
| 9 |
import streamlit as st
|
| 10 |
import altair as alt
|
| 11 |
import pandas as pd
|
|
|
|
|
|
|
| 12 |
from vega_datasets import data
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
st.subheader('This page will contain the entire dashboard.')
|
| 17 |
-
|
| 18 |
-
st.text("*Dashboard Introduction*")
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
st.text("*Brief description of Narrative*")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
st.text("*World map viz here*")
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
st.text("*Interactive viz here*")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
'''
|
| 31 |
-
####### Loading Data #######
|
| 32 |
-
|
| 33 |
-
# 1. Contracts data
|
| 34 |
-
data = pd.read_csv("/Users/sharanya/Documents/SEMESTERS/7- FALL 2024/IS445/FinalProject/IS445_VizForExperts/contract_awards_in_investment_project_financing.csv")
|
| 35 |
-
# 2. World Map dataset
|
| 36 |
-
world_map = alt.topo_feature(data.world_110m.url, feature='countries')
|
| 37 |
|
| 38 |
-
####### Loading Data #######
|
| 39 |
-
from iso3166 import countries_by_name
|
| 40 |
-
'''
|
| 41 |
|
| 42 |
-
|
| 43 |
-
import pandas as pd
|
| 44 |
-
import altair as alt
|
| 45 |
|
| 46 |
url = "contract_awards_in_investment_project_financing_22-11-2024.csv"
|
| 47 |
df = pd.read_csv(url)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns
|
| 50 |
st.header("Correlation Analysis")
|
| 51 |
|
|
@@ -71,3 +106,7 @@ correlation_plot = (
|
|
| 71 |
)
|
| 72 |
)
|
| 73 |
st.altair_chart(correlation_plot, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import streamlit as st
|
| 10 |
import altair as alt
|
| 11 |
import pandas as pd
|
| 12 |
+
import pycountry
|
| 13 |
+
import geopandas as gpd
|
| 14 |
from vega_datasets import data
|
| 15 |
|
| 16 |
+
|
| 17 |
+
st.title('World Bank Contracts Analysis')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Reading Main Data
|
|
|
|
|
|
|
| 21 |
|
| 22 |
url = "contract_awards_in_investment_project_financing_22-11-2024.csv"
|
| 23 |
df = pd.read_csv(url)
|
| 24 |
|
| 25 |
+
|
| 26 |
+
############################################################################################################
|
| 27 |
+
##################################### WORLD MAP - SHARANYA #####################################
|
| 28 |
+
|
| 29 |
+
st.header("World Map")
|
| 30 |
+
|
| 31 |
+
# Prompt for selecting country
|
| 32 |
+
st.write("Click a country to see its contract data over time")
|
| 33 |
+
|
| 34 |
+
######
|
| 35 |
+
@st.cache_data
|
| 36 |
+
def get_country_data():
|
| 37 |
+
# Mapping numeric codes to country names
|
| 38 |
+
country_data = []
|
| 39 |
+
for country in pycountry.countries:
|
| 40 |
+
try:
|
| 41 |
+
country_data.append({
|
| 42 |
+
'id': int(country.numeric),
|
| 43 |
+
'name': country.name
|
| 44 |
+
})
|
| 45 |
+
except:
|
| 46 |
+
continue
|
| 47 |
+
return pd.DataFrame(country_data)
|
| 48 |
+
|
| 49 |
+
countries = alt.topo_feature(data.world_110m.url, 'countries')
|
| 50 |
+
country_df = get_country_data()
|
| 51 |
+
|
| 52 |
+
# Interactive selection tool initialization
|
| 53 |
+
selection = alt.selection_single(fields=['name'])
|
| 54 |
+
|
| 55 |
+
# World Map with Interactions
|
| 56 |
+
map_chart = alt.Chart(countries).mark_geoshape(
|
| 57 |
+
stroke='white'
|
| 58 |
+
).transform_lookup(
|
| 59 |
+
lookup='id',
|
| 60 |
+
from_=alt.LookupData(country_df, 'id', ['name'])
|
| 61 |
+
).encode(
|
| 62 |
+
tooltip='name:N',
|
| 63 |
+
# Color changes when country is selected
|
| 64 |
+
color=alt.condition(selection,
|
| 65 |
+
alt.value('green'),
|
| 66 |
+
alt.value('lightgray')),
|
| 67 |
+
).properties(
|
| 68 |
+
width=900,
|
| 69 |
+
height=400
|
| 70 |
+
).project('naturalEarth1').add_selection(selection)
|
| 71 |
+
|
| 72 |
+
# Displaying the map
|
| 73 |
+
st.altair_chart(map_chart, use_container_width=True)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
############################################################################################################
|
| 77 |
+
##################################### TIME SERIES PLOT - JEENAL #####################################
|
| 78 |
+
|
| 79 |
+
# Code to be added
|
| 80 |
+
|
| 81 |
+
############################################################################################################
|
| 82 |
+
##################################### CORRELATION PLOT - HARSHI #####################################
|
| 83 |
+
|
| 84 |
numeric_columns = df.select_dtypes(include=['float64', 'int64']).columns
|
| 85 |
st.header("Correlation Analysis")
|
| 86 |
|
|
|
|
| 106 |
)
|
| 107 |
)
|
| 108 |
st.altair_chart(correlation_plot, use_container_width=True)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|