-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
37 lines (26 loc) · 1.12 KB
/
test.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
from dash_auth_external import DashAuthExternal
from dash import Dash, Input, Output, html, dcc
import dash
import flask
# using spotify as an example
AUTH_URL = "https://accounts.spotify.com/authorize"
TOKEN_URL = "https://accounts.spotify.com/api/token"
CLIENT_ID = "6ecc85041d924931a24d8e59e50e03f9"
# creating the instance of our auth class
auth = DashAuthExternal(AUTH_URL, TOKEN_URL, CLIENT_ID)
server = (
auth.server
) # retrieving the flask server which has our redirect rules assigned
app = Dash(__name__, server=server, use_pages=True) # instantiating our app using this server
##Below we can define our dash app like normal
app.layout = html.Div([html.Div(id="example-output"), dash.page_container, dcc.Input(id="example-input")])
@app.callback(Output("example-output", "children"), Input("example-input", "value"))
def example_callback(value):
print(auth.get_headers())
print(app.server)
token = (
auth.get_token()
) ##The token can only be retrieved in the context of a dash callback
return token
if __name__ == "__main__":
app.run_server(debug=True, host='127.0.0.1', port='8050')