-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (54 loc) · 1.91 KB
/
app.py
File metadata and controls
66 lines (54 loc) · 1.91 KB
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
import dash
from dash import dcc, html
from dash.dependencies import Input, Output, State
import plotly.graph_objs as go
from helpers import *
########### Define a few variables ######
tabtitle = 'Reddit Webscraper'
sourceurl = 'https://old.reddit.com/r/AskReddit/'
githublink = 'https://github.com/austinlasseter/reddit-webscraper-plotly'
########### Initiate the app
# external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
external_stylesheets = ['https://github.com/plotly/dash-app-stylesheets/blob/master/dash-uber-ride-demo.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.title=tabtitle
########### Layout ###########
app.layout = html.Div(children=[
html.H1('Webscraping posts from reddit'),
# Dropdowns
html.Div(children=[
html.Button('Scrape Now!', id='submit-val', n_clicks=0),
html.Div(id='message'),
dcc.Graph(id='figure-1'),
], className='twelve columns'),
# Footer
html.Br(),
html.Br(),
html.A('Code on Github', href=githublink),
html.Br(),
html.A("Data Source", href=sourceurl),
]
)
########### Callback ###########
@app.callback(
[Output('message', 'children'),
Output('figure-1', 'figure')],
[Input('submit-val', 'n_clicks')],
)
def update_output(n_clicks):
if n_clicks==0:
message = f"Click the button"
return message, base_fig()
elif n_clicks==1:
message = f"You've clicked that button {n_clicks} time!"
return message, scrape_reddit()
elif (n_clicks>1) & (n_clicks<5):
message = f"You've clicked that button {n_clicks} times!"
return message, error_fig()
else:
message = f"Seriously, stop clicking the button. You've clicked it {n_clicks} times. Nothing else is going to happen, punk!"
return message, error_fig()
############ Deploy
if __name__ == '__main__':
app.run_server(debug=True)