smomtaz commited on
Commit
3a302ae
·
verified ·
1 Parent(s): 5ec33d4

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +29 -16
server.py CHANGED
@@ -19,10 +19,10 @@ 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):
@@ -135,23 +135,36 @@ def create_server(app_dir):
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, skiprows=2)
153
- return data
154
  except Exception as e:
155
- return pd.DataFrame({"Error": [str(e)]})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  return server
 
19
 
20
  # Question-to-Sheet Mapping
21
  QUESTION_TO_SHEET = {
22
+ "What types of trips are occurring within Napa County?": "TTyp1",
23
+ "What types of inter-county trips are occurring at Napa County gateways?": "GWTTyp1",
24
+ "Where are trips into Napa County coming from?": "TT1",
25
+ "Where are trips starting and ending within Napa County?": "OD1",
26
  }
27
 
28
  def create_server(app_dir):
 
135
  #return ui.HTML(fig.to_html(full_html=False, include_plotlyjs="cdn"))
136
 
137
  @reactive.Calc
138
+ def sheet_data():
 
 
 
 
 
 
 
 
139
  sheet_name = selected_sheet()
140
  if not sheet_name:
141
+ return {"title": "No sheet selected", "data": pd.DataFrame()}
142
 
143
  try:
144
+ # Load the sheet
145
+ df = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name, skiprows=0, header=None)
146
+ # Extract title from the first row
147
+ title = df.iloc[0, 0] if not df.empty else "No title found"
148
+ # Skip the first two rows and use the third row as headers
149
  data = pd.read_excel(EXCEL_FILE, sheet_name=sheet_name, skiprows=2)
150
+ return {"title": title, "data": data}
151
  except Exception as e:
152
+ return {"title": f"Error: {str(e)}", "data": pd.DataFrame()}
153
+
154
+ # Render the table title
155
+ @output
156
+ @render.ui
157
+ def table_title():
158
+ title = sheet_data()["title"]
159
+ return ui.tags.h3(title, style="text-align: center; margin-top: 20px;")
160
+
161
+ # Render the table
162
+ @output
163
+ @render.table
164
+ def trip_table():
165
+ data = sheet_data()["data"]
166
+ if data.empty:
167
+ return pd.DataFrame({"Error": ["No data available"]})
168
+ return data
169
 
170
  return server