Spaces:
Runtime error
Runtime error
kbberendsen
commited on
Commit
•
bcf020e
1
Parent(s):
38f88c5
first attempt at reactive element
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from shiny import App, ui
|
2 |
from shinywidgets import output_widget, render_widget
|
3 |
import fastf1 as ff1
|
4 |
import matplotlib.pyplot as plt
|
@@ -18,10 +18,8 @@ app_ui = ui.page_fluid(
|
|
18 |
)
|
19 |
|
20 |
def server(input, output, session):
|
21 |
-
@
|
22 |
-
|
23 |
-
def my_widget():
|
24 |
-
|
25 |
ff1.Cache.enable_cache('.\cache')
|
26 |
|
27 |
session = ff1.get_session(2023, input.track, 'R')
|
@@ -37,7 +35,11 @@ def server(input, output, session):
|
|
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 |
|
|
|
|
|
|
|
41 |
cmap = cm.get_cmap('Paired')
|
42 |
lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
|
43 |
lc_comp.set_array(gear)
|
@@ -48,15 +50,15 @@ def server(input, output, session):
|
|
48 |
plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
|
49 |
|
50 |
title = plt.suptitle(
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
|
56 |
cbar.set_ticks(np.arange(1.5, 9.5))
|
57 |
cbar.set_ticklabels(np.arange(1, 9))
|
58 |
-
|
59 |
-
|
60 |
|
61 |
|
62 |
app = App(app_ui, server)
|
|
|
1 |
+
from shiny import App, ui, render, reactive
|
2 |
from shinywidgets import output_widget, render_widget
|
3 |
import fastf1 as ff1
|
4 |
import matplotlib.pyplot as plt
|
|
|
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')
|
|
|
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)
|
|
|
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))
|
59 |
cbar.set_ticklabels(np.arange(1, 9))
|
60 |
+
|
61 |
+
return plt
|
62 |
|
63 |
|
64 |
app = App(app_ui, server)
|