-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
95 lines (78 loc) · 2.31 KB
/
app.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
# -*- coding: utf-8 -*-
"""
"""
__author__ = "Vegard Ulriksen Solberg"
__email__ = "[email protected]"
import dash
from dash import dcc
import dash_bootstrap_components as dbc
from dash import html
from src.utils import (
mandelbrot_figure,
card_color,
card_max_iter,
card_resolution,
coordinates,
relayout_map,
)
from dash.dependencies import Input, Output
MAX_ITER = 300
RESOLUTION = 500
SWITCH_NR = 5
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
def create_sliders():
return [
html.Br(),
html.Br(),
dbc.Card(card_color, color="light", inverse=False),
dbc.Card(card_max_iter, color="light", inverse=False),
dbc.Card(card_resolution, color="light", inverse=False),
]
layout = html.Div(
[
html.Br(),
html.H1(id="header", children="Mandelbrot"),
html.P(
id="info-text",
children="Explore the mandelbrot set by zooming in the figure",
),
dbc.Row(
[
dbc.Col(
dcc.Graph(
id="mandelbrot-fig",
figure=mandelbrot_figure(
max_iter=MAX_ITER,
resolution=RESOLUTION,
switch_nr=SWITCH_NR,
),
),
md=8,
),
dbc.Col(create_sliders(), md=3),
]
),
]
)
app.layout = layout
@app.callback(
Output("mandelbrot-fig", "figure"),
[
Input("mandelbrot-fig", "relayoutData"),
Input("color-slider", "value"),
Input("resolution-slider", "value"),
Input("max-iter-slider", "value"),
],
)
def update_data(relayoutData, switch_nr, resolution, max_iter):
kwargs = {"max_iter": max_iter, "resolution": resolution, "switch_nr": switch_nr}
if relayoutData is None:
kwargs.update(coordinates)
elif any(["axis.range" in key for key in list(relayoutData.keys())]):
new_coordinates = {relayout_map[key]: relayoutData[key] for key in relayoutData}
coordinates.update(new_coordinates)
kwargs.update(coordinates)
return mandelbrot_figure(**kwargs)
if __name__ == "__main__":
app.run_server(debug=True)