smomtaz commited on
Commit
e79ca1c
·
verified ·
1 Parent(s): 260d0ed

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +83 -75
server.py CHANGED
@@ -1,75 +1,83 @@
1
- # server.py
2
- import matplotlib.pyplot as plt
3
- from shiny import render, ui
4
- import faicons as fa
5
- #from fontawesomefree import icons
6
-
7
-
8
- def create_server(app_dir):
9
- def server(input, output, session):
10
- @render.image
11
- def logo():
12
- img = {
13
- "src": app_dir / "images" / "logo.png",
14
- "style": "width: 80%; height: auto; max-height: 150px; margin-bottom: 0px;"
15
- }
16
- return img
17
-
18
- @render.plot
19
- def bar_chart():
20
- # Sample data for bar chart
21
- categories = ["Category A", "Category B", "Category C"]
22
- values = [10, 20, 30]
23
-
24
- fig, ax = plt.subplots()
25
- ax.bar(categories, values, color=["#1f77b4", "#ff7f0e", "#2ca02c"])
26
- ax.set_title("Bar Chart Example")
27
- ax.set_ylabel("Values")
28
- ax.set_xlabel("Categories")
29
-
30
- return fig
31
-
32
- @render.plot
33
- def pie_chart():
34
- # Data for pie chart
35
- labels = ["Home-Based Work", "Home-Based Other", "Non-Home-Based"]
36
- #labels = [f"{icons['fa-car']} Cars", f"{icons['fa-bicycle']} Bikes", f"{icons['fa-bus']} Buses"]
37
- #labels = [f"{fa.icon_svg("briefcase")} Cars", f"{fa.icon_svg("briefcase")} Bikes", f"{fa.icon_svg("briefcase")} Buses"]
38
-
39
-
40
- sizes = [22, 41, 37]
41
- colors = ["#00b3b3", "#70d281", "#ff7f0e"]
42
- explode = (0.1, 0, 0) # Explode the first slice for emphasis
43
-
44
- fig, ax = plt.subplots()
45
- wedges, texts, autotexts = ax.pie(
46
- sizes,
47
- explode=explode,
48
- labels=labels,
49
- autopct="%1.0f%%",
50
- startangle=90,
51
- colors=colors,
52
- textprops=dict(color="black"),
53
- wedgeprops=dict(width=0.4) # Adjust width for the donut effect
54
- )
55
-
56
- # Customizing the labels
57
- for text, label in zip(autotexts, labels):
58
- text.set_color("black")
59
- text.set_fontsize(12)
60
-
61
- # Generate the SVG icons as strings
62
- #briefcase_icon = fa.icon_svg("briefcase", fill="#00b3b3")
63
- #shopping_cart_icon = fa.icon_svg("cart-shopping", fill="#70d281")
64
- #map_marker_icon = fa.icon_svg("umbrella-beach", fill="#ff7f0e")
65
-
66
- # Add the SVG icons to the plot
67
- #ax.text(-1.5, 0.7, briefcase_icon, ha="center", va="center", fontsize=12)
68
- #ax.text(1.5, 0.7, shopping_cart_icon, ha="center", va="center", fontsize=12)
69
- #ax.text(0, -1.3, map_marker_icon, ha="center", va="center", fontsize=12)
70
-
71
- # Title styling
72
- #ax.set_title("Trip Purposes", fontsize=16, fontweight="bold")
73
- return fig
74
-
75
- return server
 
 
 
 
 
 
 
 
 
1
+ # server.py
2
+ import matplotlib.pyplot as plt
3
+ from shiny import render, ui
4
+ import faicons as fa
5
+ #from fontawesomefree import icons
6
+
7
+
8
+ def create_server(app_dir):
9
+ def server(input, output, session):
10
+ @render.image
11
+ def logo():
12
+ img = {
13
+ "src": app_dir / "images" / "logo.png",
14
+ "style": "width: 80%; height: auto; max-height: 150px; margin-bottom: 0px;"
15
+ }
16
+ return img
17
+
18
+ @render.image
19
+ def logo2():
20
+ img = {
21
+ "src": app_dir / "images" / "logo2.png",
22
+ "style": "width: 80%; height: auto; max-height: 150px; margin-bottom: 0px;"
23
+ }
24
+ return img
25
+
26
+ @render.plot
27
+ def bar_chart():
28
+ # Sample data for bar chart
29
+ categories = ["Category A", "Category B", "Category C"]
30
+ values = [10, 20, 30]
31
+
32
+ fig, ax = plt.subplots()
33
+ ax.bar(categories, values, color=["#1f77b4", "#ff7f0e", "#2ca02c"])
34
+ ax.set_title("Bar Chart Example")
35
+ ax.set_ylabel("Values")
36
+ ax.set_xlabel("Categories")
37
+
38
+ return fig
39
+
40
+ @render.plot
41
+ def pie_chart():
42
+ # Data for pie chart
43
+ labels = ["Home-Based Work", "Home-Based Other", "Non-Home-Based"]
44
+ #labels = [f"{icons['fa-car']} Cars", f"{icons['fa-bicycle']} Bikes", f"{icons['fa-bus']} Buses"]
45
+ #labels = [f"{fa.icon_svg("briefcase")} Cars", f"{fa.icon_svg("briefcase")} Bikes", f"{fa.icon_svg("briefcase")} Buses"]
46
+
47
+
48
+ sizes = [22, 41, 37]
49
+ colors = ["#00b3b3", "#70d281", "#ff7f0e"]
50
+ explode = (0.1, 0, 0) # Explode the first slice for emphasis
51
+
52
+ fig, ax = plt.subplots()
53
+ wedges, texts, autotexts = ax.pie(
54
+ sizes,
55
+ explode=explode,
56
+ labels=labels,
57
+ autopct="%1.0f%%",
58
+ startangle=90,
59
+ colors=colors,
60
+ textprops=dict(color="black"),
61
+ wedgeprops=dict(width=0.4) # Adjust width for the donut effect
62
+ )
63
+
64
+ # Customizing the labels
65
+ for text, label in zip(autotexts, labels):
66
+ text.set_color("black")
67
+ text.set_fontsize(12)
68
+
69
+ # Generate the SVG icons as strings
70
+ #briefcase_icon = fa.icon_svg("briefcase", fill="#00b3b3")
71
+ #shopping_cart_icon = fa.icon_svg("cart-shopping", fill="#70d281")
72
+ #map_marker_icon = fa.icon_svg("umbrella-beach", fill="#ff7f0e")
73
+
74
+ # Add the SVG icons to the plot
75
+ #ax.text(-1.5, 0.7, briefcase_icon, ha="center", va="center", fontsize=12)
76
+ #ax.text(1.5, 0.7, shopping_cart_icon, ha="center", va="center", fontsize=12)
77
+ #ax.text(0, -1.3, map_marker_icon, ha="center", va="center", fontsize=12)
78
+
79
+ # Title styling
80
+ ax.set_title("What Types of Trips are Occuring within Napa County on a Weekday?", fontsize=16, fontweight="bold")
81
+ return fig
82
+
83
+ return server