aboutsummaryrefslogtreecommitdiff
path: root/app.py
blob: a2e9f07fe409d80c828f6465846da6fd7268487b (plain)
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
from dash import Dash, dcc, html, Input, Output
import plotly.graph_objects as go
import json
import datetime

app = Dash(__name__)


app.layout = html.Div([
    html.H4('Interactive color selection with simple Dash example'),
    html.P("Select color:"),
    dcc.Dropdown(
        id="dropdown",
        options=['Gold', 'MediumTurquoise', 'LightGreen'],
        value='Gold',
        clearable=False,
    ),
    dcc.Graph(id="graph"),
])

# pull stock data from json files
timestamps_file = open('timestamps.json', 'r')
timestamps_file_data = timestamps_file.read()
timestamps = json.loads(timestamps_file_data)
timestamps = [datetime.datetime.fromtimestamp(t) for t in timestamps]

prices_file = open('close_prices.json', 'r')
prices = json.loads(prices_file.read())

# print('timestamps:\t', timestamps, '\nprices:\t', prices)


@app.callback(
    Output("graph", "figure"),
    Input("dropdown", "value"))
def display_color(color):
    fig = go.Figure(
        data=go.Line(x=timestamps, y=prices, marker_color=color))
    return fig


app.run(debug=True)