kenken999 commited on
Commit
647d1d5
1 Parent(s): b9cf572
Files changed (1) hide show
  1. routers/postg/gradio_app.py +8 -5
routers/postg/gradio_app.py CHANGED
@@ -126,10 +126,13 @@ def crud_interface():
126
  return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
127
 
128
  def load_ride_details(evt: gr.SelectData):
129
- ride_id = int(evt.value[0]) # クリックした行のride_idを取得
130
- ride = read_ride(ride_id)
131
- if ride:
132
- return ride[1], ride[2], ride[3], ride[4], ride[5], ride[6], ride[7], ride[8], ride[0]
 
 
 
133
 
134
  create_button.click(fn=create_ride_click,
135
  inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual],
@@ -140,7 +143,7 @@ def crud_interface():
140
  delete_button.click(fn=delete_ride_click, inputs=ride_id, outputs=output)
141
  read_button.click(fn=read_rides_click, outputs=output)
142
 
143
- output.select(load_ride_details, inputs=None, outputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual, ride_id])
144
 
145
  return interface
146
 
 
126
  return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
127
 
128
  def load_ride_details(evt: gr.SelectData):
129
+ selected_data = evt.value
130
+ if selected_data:
131
+ ride_id = selected_data[0]
132
+ ride = read_ride(ride_id)
133
+ if ride:
134
+ return ride[1], ride[2], ride[3], ride[4], ride[5], ride[6], ride[7], ride[8], ride[0]
135
+ return "", 0, "", 0, "", "", "", "", -1
136
 
137
  create_button.click(fn=create_ride_click,
138
  inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual],
 
143
  delete_button.click(fn=delete_ride_click, inputs=ride_id, outputs=output)
144
  read_button.click(fn=read_rides_click, outputs=output)
145
 
146
+ output.select(fn=load_ride_details, inputs=None, outputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual, ride_id])
147
 
148
  return interface
149