-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.py
148 lines (122 loc) · 6.08 KB
/
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
import clean_collected_data
from bot import main
from get_sentimet import generate_sentiments
from clean_collected_data import preprocess_data
import plotly.graph_objects as go
URL = 'https://twitter.com/elonmusk/status/1388693126206918658'
usr = "breenda.das@gmail.com"
pwd = "Bree@1807"
file_path = 'collected_data.csv'
def get_data(url):
main(usr, pwd,file_path,url)
data, small_data = preprocess_data()
return data, small_data
dash_app = dash.Dash(__name__)
dash_app.layout = html.Div([
dcc.Input(id="input-url", type="url", value=URL),
dcc.Graph(id="sentiment-time-series-chart"),
dcc.Graph(id="user-comment-insights"),
dcc.Graph(id = "Top-Tweets-Insights")
])
@dash_app.callback(
Output('sentiment-time-series-chart', 'figure'),
Output('user-comment-insights', 'figure'),
Output('Top-Tweets-Insights', 'figure'),
Input('input-url', 'value'))
def update_insights(url):
df,small_df = get_data(url)
fig1 = go.Figure(data=go.Scatter(x=df['datetime'],
y=df['sentiments'],
mode='markers',
marker_color=df['sentiments'],
text=df['username']))
fig1.update_layout(title = 'Sentiment analysis with Tweet Replies Date Time',
xaxis= dict(title= 'Date Time',gridcolor='lightgrey'),
yaxis= dict(title= 'Sentiment Score',showgrid=False),
plot_bgcolor='rgba(0,0,0,0)')
fig2 = px.scatter(df, x="comment_likes", y="comment_retweets", size="comment_replies", color="sentiments",
hover_name="comment",log_x = True)
fig2.update_layout(title = 'Reply Statistics Table: Reply Retweets, Reply Likes, Reply Comment Count',plot_bgcolor='rgba(0,0,0,0.1)',yaxis= dict(showgrid=False))
colors = ['rgb(239, 243, 255)', 'rgb(189, 215, 231)', 'rgb(107, 174, 214)',
'rgb(49, 130, 189)', 'rgb(8, 81, 156)']
small_df['Color'] = colors
fig3 = go.Figure(data=[go.Table(
header=dict(
values=["comment", "comment_likes","comment_sentiment"],
line_color='white', fill_color='white',
align='center', font=dict(color='black', size=12)
),
cells=dict(
values=[small_df['Comment'], small_df['Comment Likes'],small_df['Comment Sentiment Score']],
line_color=[small_df.Color], fill_color=[small_df.Color],
align='center', font=dict(color='black', size=11)
))
])
fig3.update_layout(title = 'Popular User Statistics')
return fig1, fig2, fig3
# fig1 = go.Figure(data=go.Scatter(x=df['datetime'],
# y=df['sentiments'],
# mode='markers',
# marker_color=df['sentiments'],
# text=df['username']))
# fig1.update_layout(title = 'Sentiment analysis with Tweet Replies Date Time',
# xaxis= dict(title= 'Date Time',gridcolor='lightgrey'),
# yaxis= dict(title= 'Sentiment Score',showgrid=False),
# plot_bgcolor='rgba(0,0,0,0)')
# ## scatter plot comment likes, comment retweets, place
# fig2 = px.scatter(df, x="comment_likes", y="comment_retweets", size="comment_replies", color="sentiments",
# hover_name="comment",log_x = True)
# fig2.update_layout(title = 'Reply Statistics Table: Reply Retweets, Reply Likes, Reply Comment Count',plot_bgcolor='rgba(0,0,0,0.1)',yaxis= dict(showgrid=False))
# colors = ['rgb(239, 243, 255)', 'rgb(189, 215, 231)', 'rgb(107, 174, 214)',
# 'rgb(49, 130, 189)', 'rgb(8, 81, 156)']
# small_df['Color'] = colors
# fig3 = go.Figure(data=[go.Table(
# header=dict(
# values=["comment", "comment_likes","comment_sentiment"],
# line_color='white', fill_color='white',
# align='center', font=dict(color='black', size=12)
# ),
# cells=dict(
# values=[small_df['Comment'], small_df['Comment Likes'],small_df['Comment Sentiment Score']],
# line_color=[small_df.Color], fill_color=[small_df.Color],
# align='center', font=dict(color='black', size=11)
# ))
# ])
# fig3.update_layout(title = 'Popular User Statistics')
# markdown_text1 = '''
# # Insights on your Twitter Post
# The dashboard presents visuals on the analysis conducted on the user response data on your twitter post.
# The dashboard gives an overview of the sentiment analysis of the tweet replies recorded over the span of posting date and today.
# ## Sentiment Analysis
# The first graph depicts **Sentiment Analysis of Replies** on your twitter post.This graph shows how the sentiments
# of reaction of users on your post have changed or evolved over time. This graph is useful to understand the twitter post popularity
# over time and general reaction over time.
# '''
# markdown_text2 = '''
# ## User Comment Insights
# The second graph depicts **User Data Statistics** on your twitter post. This graph shows the popular reply stats on your post
# that may prove useful as an important customer review feedback. The graph plots 3 useful features, the reply user likes, comment and retweets,
# hovered by the reply comment for reference.
# This is a very valuable customer review graph.
# '''
# markdown_text3 = '''
# ## Popular Reply Sentiments
# The third graph shows a tabular representation of the **Sentiments of the five most popular by likes user comments** on your tweet. These statistics give
# an insight of the general impression of your post. A very good popular post makes a good about your twitter post, while a
# negetive feed back may prove useful to your company.
# '''
# app.layout = html.Div([
# dcc.Markdown(children=markdown_text1),
# dcc.Graph(id="sentiment-time-series-chart",figure=fig1),
# dcc.Markdown(children=markdown_text2),
# dcc.Graph(id="user comment insights",figure=fig2),
# dcc.Markdown(children=markdown_text3),
# dcc.Graph(id = "Top Tweets Insights", figure = fig3)
# ])
dash_app.run_server(debug=True)