Update server.py
Browse files
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.
|
| 19 |
-
def
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|