-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstreamlit_mpx_app.py
87 lines (72 loc) · 3.05 KB
/
streamlit_mpx_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
# """
# Streamlit Monkeypox Tweets MVP
# """
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud
st.set_page_config(layout="wide")
st.markdown("<h1 style='text-align: center; color: #1DA1F2;'>Monkeypox Tweet Dashboard</h1>", unsafe_allow_html=True)
st.write("#")
col1, col2, col3 = st.columns([1, 2, 2], gap="medium")
# ----Tweet Metrics----
with col1:
# st.header("Tweet Metrics")
st.metric(label="Tweets", value="28,498")
with col1:
st.metric(label="Handles", value="15,990")
# ----Topic Word Cloud----
with col2:
st.write("### Topic Word Cloud")
topic1 = 'emergency, global, spreading, cdc, biden, pandemic, said, risk, day, yet, even, may, could, government, coming, children, fear, foxnews, states, stop'
topic2 = 'vaccine, smallpox, cdc, vaccines, shingles, yet, day, states, risk, everyone, vax, make, foxnews, biden, also, many, even, government, really, since'
topic3 = 'gay, men, sex, community, spreading, aids, cdc, stop, contact, man, children, month, risk, say, way, said, anyone, everyone, since, many'
topic4 = 'cnn, biden, trump, real, democrats, states, make, msnbc, good, years, man, please, said, since, day, never, let, right, say, even'
topic5 = 'dont, pandemic, see, moneypox, well, im, still, right, say, vaccines, even, thing, back, way, good, really, stop, biden, make, coming'
topic = st.selectbox('Select a topic:',['risk','vaccine','gay men', 'news', 'mix'])
def create_wordcloud(topic):
if topic == 'risk':
topic = topic1
elif topic == 'vaccine':
topic = topic2
elif topic == 'gay men':
topic = topic3
elif topic == 'news':
topic = topic4
else:
topic = topic5
wordcloud = WordCloud().generate(topic)
return wordcloud
wordcloud = create_wordcloud(topic)
fig, ax = plt.subplots(figsize = (12, 12))
ax.imshow(wordcloud)
plt.axis("off")
st.pyplot(fig)
# ----Tweets by Date----
@st.cache
def load_date_data():
data = pd.read_csv('date_df.csv')
return data
# st.write("#")
with col2:
st.write("#")
st.write("### Tweets by Date")
date_data = load_date_data()
date_df = pd.DataFrame(date_data, columns = ['date', 'tweets_per_day'])
st.line_chart(date_df, x='date', y='tweets_per_day')
# ----Tweet Text----
with col1:
st.write("#")
st.write("### Monkeypox Tweets")
tweets = pd.read_csv('tweets.csv')
tweets = tweets[['date', 'text']]
st.dataframe(tweets)
st.markdown('Source: [Kaggle](https://www.kaggle.com/datasets/thakurnirmalya/monkeypox2022tweets)')
# ----State Case Counts----
with col3:
st.write("### State Case Counts")
data = pd.read_csv('state_cases_for_map.csv')
input = st.slider('Slide for state counts:', int(data['cases'].min()),int(data['cases'].max()), 3500 )
filter = data['cases'] < input
st.map(data.loc[filter, ['lat', 'lon']])
st.markdown('Source: [CDC 2022 U.S. Map & Case Count](https://www.cdc.gov/poxvirus/monkeypox/response/2022/index.html)')