kbberendsen commited on
Commit
87aae5e
·
1 Parent(s): fef44ff

Update reactive structure

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -6,6 +6,8 @@ from matplotlib.collections import LineCollection
6
  from matplotlib import cm
7
  import numpy as np
8
 
 
 
9
  app_ui = ui.page_fluid(
10
  ui.div(
11
  ui.input_select(
@@ -14,13 +16,13 @@ app_ui = ui.page_fluid(
14
  ),
15
  class_="d-flex gap-3"
16
  ),
17
- output_widget("my_widget")
18
  )
19
 
20
  def server(input, output, session):
21
  @reactive.Calc
22
  def get_data():
23
- ff1.Cache.enable_cache('.\cache')
24
 
25
  session = ff1.get_session(2023, input.track, 'R')
26
  session.load()
@@ -35,11 +37,17 @@ def server(input, output, session):
35
  points = np.array([x, y]).T.reshape(-1, 1, 2)
36
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
37
  gear = tel['nGear'].to_numpy().astype(float)
38
- return lap, tel, x,y,points,segments,gear
39
 
40
  @output
41
  @render_widget
42
- def my_widget(lap, tel, x,y,points,segments,gear):
 
 
 
 
 
 
43
  cmap = cm.get_cmap('Paired')
44
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
45
  lc_comp.set_array(gear)
@@ -49,10 +57,10 @@ def server(input, output, session):
49
  plt.axis('equal')
50
  plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
51
 
52
- title = plt.suptitle(
53
- f"Fastest Lap Gear Shift Visualization\n"
54
- f"{lap['Driver']} - {session.event['EventName']} {session.event.year}"
55
- )
56
 
57
  cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
58
  cbar.set_ticks(np.arange(1.5, 9.5))
 
6
  from matplotlib import cm
7
  import numpy as np
8
 
9
+ ff1.Cache.enable_cache('.\cache')
10
+
11
  app_ui = ui.page_fluid(
12
  ui.div(
13
  ui.input_select(
 
16
  ),
17
  class_="d-flex gap-3"
18
  ),
19
+ ui.output_plot("gear")
20
  )
21
 
22
  def server(input, output, session):
23
  @reactive.Calc
24
  def get_data():
25
+
26
 
27
  session = ff1.get_session(2023, input.track, 'R')
28
  session.load()
 
37
  points = np.array([x, y]).T.reshape(-1, 1, 2)
38
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
39
  gear = tel['nGear'].to_numpy().astype(float)
40
+ return lap, tel, x, y, points, segments, gear
41
 
42
  @output
43
  @render_widget
44
+ def gear():
45
+ lap = get_data().lap
46
+ tel = get_data().tel
47
+ points = get_data().points
48
+ segments = get_data().segments
49
+
50
+
51
  cmap = cm.get_cmap('Paired')
52
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
53
  lc_comp.set_array(gear)
 
57
  plt.axis('equal')
58
  plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
59
 
60
+ ##title = plt.suptitle(
61
+ ## f"Fastest Lap Gear Shift Visualization\n"
62
+ ## f"{lap['Driver']} - {session.event['EventName']} {session.event.year}"
63
+ ## )
64
 
65
  cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
66
  cbar.set_ticks(np.arange(1.5, 9.5))