-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpotify_Dashboard.py
85 lines (74 loc) · 2.92 KB
/
Spotify_Dashboard.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
import streamlit as st
import pandas_gbq
from google.oauth2 import service_account
import folium
from folium.plugins import MarkerCluster
from streamlit_folium import st_folium
from streamlit_extras.let_it_rain import rain
# bigquery
credentials = service_account.Credentials.from_service_account_info(
st.secrets["gcp_service_account"]
)
project_id = st.secrets["gcp_service_account"]["project_id"]
spotify_data = "spotify"
table = "universal_top_spotify_songs"
query = f"""
SELECT DISTINCT artists, country, name, is_explicit, speechiness, danceability, acousticness, liveness
FROM `{project_id}.{spotify_data}.{table}`
WHERE country IN ('IT','US','FR','ES','MX')
"""
spotify_data = pandas_gbq.read_gbq(query, project_id=project_id, credentials=credentials)
# cleaning the data
spotify_data["artists"] = spotify_data["artists"].astype(str).str.split(", ")
spotify_data2 = spotify_data.explode("artists")
spotify_data2["artists"] = spotify_data2["artists"].str.strip("[]'\" ")
#intro
LOGO_URL_SMALL = "https://storage.googleapis.com/pr-newsroom-wp/1/2023/05/Spotify_Full_Logo_RGB_Green.png"
st.logo(
LOGO_URL_SMALL,
link="https://storage.googleapis.com/pr-newsroom-wp/1/2023/05/Spotify_Full_Logo_RGB_Green.png",
icon_image=LOGO_URL_SMALL,
)
st.title("Spotify Streaming Analysis")
st.header("by Alexa and Giulio")
st.write("Thanks for stopping by our dashboard! This app uses Kaggle's \"Top Spotify Songs in 73 Countries (Daily Updated)\" dataset to analyze music trends across the world. Hope you enjoy!")
st.markdown("[Link to dataset](https://www.kaggle.com/datasets/asaniczka/top-spotify-songs-in-73-countries-daily-updated?resource=download)")
def rain_emojis(emoji):
rain(
emoji=emoji,
font_size=54,
falling_speed=10,
animation_length=5,
)
rain_emojis("🎵")
#creating list of coordinates and corresponding pages
locations = {
"Italy": [41.8719, 12.5674, "pages/Italy.py"],
"United States": [38.79468, -74.0060, "pages/United_States.py"],
"Mexico": [19.4326, -99.1332, "pages/Mexico.py"],
"France": [46.6034, 1.8883, "pages/France.py"],
"Spain": [40.4637, -3.7492, "pages/Spain.py"]
}
#setting initial location for map
map = folium.Map(location=[46.1101, -37.0669], zoom_start=2)
#adding country markers on map
marker_cluster = MarkerCluster().add_to(map)
for country, (lat, lon, page) in locations.items():
folium.Marker(
location=[lat, lon],
popup=country,
tooltip=country,
icon=folium.Icon(color='blue')
).add_to(marker_cluster)
#choosing country
selection = st.pills(
"Select a country:",
options=list(locations.keys()),
)
# Automatically redirect if a selection is made
if selection:
st.switch_page(locations[selection][2])
#display map
st.write("Check out this map to see which countries we feature on our app:")
st_folium(map, width=700, height=500)
#streamlit run Spotify_Dashboard.py