smomtaz commited on
Commit
eb468eb
·
verified ·
1 Parent(s): 33509eb

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +31 -1
server.py CHANGED
@@ -14,6 +14,17 @@ import plotly.graph_objects as go
14
  # Load the data
15
  zones, trips = load_data()
16
 
 
 
 
 
 
 
 
 
 
 
 
17
  def create_server(app_dir):
18
  def server(input, output, session):
19
 
@@ -122,6 +133,25 @@ def create_server(app_dir):
122
  return fig
123
  #return ui.HTML(fig.to_html())
124
  #return ui.HTML(fig.to_html(full_html=False, include_plotlyjs="cdn"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
-
127
  return server
 
14
  # Load the data
15
  zones, trips = load_data()
16
 
17
+ # Path to Excel file
18
+ EXCEL_FILE = "data/trips_data.xlsx" # Update with your file path
19
+
20
+ # Question-to-Sheet Mapping
21
+ QUESTION_TO_SHEET = {
22
+ "What types of trips are occurring within Napa County?": "Sheet1",
23
+ "What types of inter-county trips are occurring at Napa County gateways?": "Sheet2",
24
+ "Where are trips into Napa County coming from?": "Sheet3",
25
+ "Where are trips starting and ending within Napa County?": "Sheet4",
26
+ }
27
+
28
  def create_server(app_dir):
29
  def server(input, output, session):
30
 
 
133
  return fig
134
  #return ui.HTML(fig.to_html())
135
  #return ui.HTML(fig.to_html(full_html=False, include_plotlyjs="cdn"))
136
+
137
+ @reactive.Calc
138
+ def selected_sheet():
139
+ """Get the corresponding sheet name for the selected question."""
140
+ question = input.question_selector()
141
+ return QUESTION_TO_SHEET.get(question, None)
142
+
143
+ # Render table for the selected sheet
144
+ @output
145
+ @render.table
146
+ def trip_table():
147
+ sheet_name = selected_sheet()
148
+ if not sheet_name:
149
+ return pd.DataFrame({"Error": ["No sheet selected or invalid question"]})
150
+
151
+ try:
152
+ data = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name)
153
+ return data
154
+ except Exception as e:
155
+ return pd.DataFrame({"Error": [str(e)]})
156
 
 
157
  return server