Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import dash
|
| 2 |
+
from dash import dcc, html, Input, Output,dash_table
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
toxicTweetsDataFrame = pd.read_csv('ProcessedTweets.csv')
|
| 8 |
+
|
| 9 |
+
dashAppValue = dash.Dash(__name__)
|
| 10 |
+
|
| 11 |
+
dashAppValue.layout = html.Div([
|
| 12 |
+
html.H1("Social Media Dashboard", style={'textAlign': 'center'}),
|
| 13 |
+
|
| 14 |
+
html.Div([
|
| 15 |
+
html.Div([
|
| 16 |
+
html.Label('Choose the respective month'),
|
| 17 |
+
dcc.Dropdown(
|
| 18 |
+
id='dropdown-month-value',
|
| 19 |
+
options=[{'modifedLabel': month, 'respectiveValue': month} for month in toxicTweetsDataFrame['Month'].unique()],
|
| 20 |
+
value=toxicTweetsDataFrame['Month'].unique()[0],
|
| 21 |
+
clearable=False,
|
| 22 |
+
style={'width': '100%'}
|
| 23 |
+
)
|
| 24 |
+
], style={'width': '30%', 'display': 'inline-block', 'margin': 'auto'}),
|
| 25 |
+
|
| 26 |
+
html.Div([
|
| 27 |
+
html.Label('Range Slider Value'),
|
| 28 |
+
dcc.RangeSlider(
|
| 29 |
+
id='sentimentAppValue',
|
| 30 |
+
min=toxicTweetsDataFrame['Sentiment'].min(),
|
| 31 |
+
max=toxicTweetsDataFrame['Sentiment'].max(),
|
| 32 |
+
value=[toxicTweetsDataFrame['Sentiment'].min(), toxicTweetsDataFrame['Sentiment'].max()]
|
| 33 |
+
)
|
| 34 |
+
], style={'width': '30%', 'display': 'inline-block', 'margin': 'auto'}),
|
| 35 |
+
html.Div([
|
| 36 |
+
html.Label('Subjectivity Range'),
|
| 37 |
+
dcc.RangeSlider(
|
| 38 |
+
id='sliderRelativity',
|
| 39 |
+
min=toxicTweetsDataFrame['Subjectivity'].min(),
|
| 40 |
+
max=toxicTweetsDataFrame['Subjectivity'].max(),
|
| 41 |
+
value=[toxicTweetsDataFrame['Subjectivity'].min(), toxicTweetsDataFrame['Subjectivity'].max()]
|
| 42 |
+
)
|
| 43 |
+
], style={'width': '30%', 'display': 'inline-block', 'margin': 'auto'})
|
| 44 |
+
], style={'textAlign': 'center', 'margin-bottom': '20px'}),
|
| 45 |
+
|
| 46 |
+
dcc.Graph(id='modified-scatterplot'),
|
| 47 |
+
dash_table.DataTable(
|
| 48 |
+
id='modified-tweet-Value',
|
| 49 |
+
data=[],
|
| 50 |
+
columns=[{'modifiedName':'RawTweet','modifiedId': 'RawTweet'}],
|
| 51 |
+
page_size=10,
|
| 52 |
+
style_table={'overflowX': 'auto', 'width': '100%', 'margin': 'auto'},
|
| 53 |
+
style_cell={'textAlign': 'center', 'minWidth': '100px', 'width': '100px', 'maxWidth': '200px'}
|
| 54 |
+
)
|
| 55 |
+
])
|
| 56 |
+
|
| 57 |
+
@dashAppValue.callback(
|
| 58 |
+
Output('modified-scatterplot', 'figure'),
|
| 59 |
+
[Input('dropdown-month-value', 'value'),
|
| 60 |
+
Input('sentimentAppValue', 'value'),
|
| 61 |
+
Input('sliderRelativity', 'value')]
|
| 62 |
+
)
|
| 63 |
+
def modifiedScatterplotValue(chosenMonthValue, rangeValueSlider, rangeRelativitySlider):
|
| 64 |
+
modifiedDataFrame = toxicTweetsDataFrame[(toxicTweetsDataFrame['Month'] == chosenMonthValue) &
|
| 65 |
+
(toxicTweetsDataFrame['Sentiment'] >= rangeValueSlider[0]) & (toxicTweetsDataFrame['Sentiment'] <= rangeValueSlider[1]) &
|
| 66 |
+
(toxicTweetsDataFrame['Subjectivity'] >= rangeRelativitySlider[0]) & (toxicTweetsDataFrame['Subjectivity'] <= rangeRelativitySlider[1])]
|
| 67 |
+
generatedFigureValue = px.scatter(modifiedDataFrame, x='Dimension 1', y='Dimension 2', hover_data=['RawTweet'])
|
| 68 |
+
generatedFigureValue.update_layout(title=None, xaxis_title=None, yaxis_title=None, modebar={'orientation': 'v'})
|
| 69 |
+
return generatedFigureValue
|
| 70 |
+
|
| 71 |
+
@dashAppValue.callback(
|
| 72 |
+
Output('modifiedTweetValue', 'data'),
|
| 73 |
+
[Input('modified-scatterplot', 'selectedData')]
|
| 74 |
+
)
|
| 75 |
+
def showRespectiveTweets(chosenDataPoint):
|
| 76 |
+
if chosenDataPoint and 'updatedEntries' in chosenDataPoint:
|
| 77 |
+
chosenMessages = []
|
| 78 |
+
for respectivePoint in chosenDataPoint['updatedEntries']:
|
| 79 |
+
chosenTextPoint = chosenDataPoint['dataValue'][0]
|
| 80 |
+
chosenMessages.append(chosenTextPoint)
|
| 81 |
+
accurateDataValues = pd.DataFrame(chosenMessages ,columns = ['RawTweet'])
|
| 82 |
+
|
| 83 |
+
print(accurateDataValues)
|
| 84 |
+
toxicTweetsDataFrame = accurateDataValues.to_dict(orient ='records')
|
| 85 |
+
return toxicTweetsDataFrame
|
| 86 |
+
else:
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if __name__ == '__main__':
|
| 91 |
+
dashAppValue.run_server(debug=True)
|