Geraldine commited on
Commit
4a99d36
·
verified ·
1 Parent(s): 4e3844d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -32
app.py CHANGED
@@ -72,8 +72,8 @@ app.layout = html.Div([
72
 
73
  # Tabs
74
  dcc.Tabs(id="data-tabs", value="api", children=[
75
- dcc.Tab(label="From Omeka S", value="omeka"),
76
- dcc.Tab(label="From LanceDB", value="lance")
77
  ]),
78
 
79
  html.Div(id="data-tab-content"),
@@ -250,7 +250,7 @@ def render_tab_content(tab):
250
  if tab == "omeka":
251
  return html.Div([
252
  html.Div([
253
- html.H5("From Omeka S", className="mb-3"),
254
  # API URL input with full width
255
  dbc.InputGroup([
256
  dbc.Input(
@@ -310,11 +310,21 @@ def render_tab_content(tab):
310
  ], className="border rounded bg-white shadow-sm")
311
  elif tab == "lance":
312
  return html.Div([
313
- html.H5("From LanceDB"),
314
- dbc.Button("Load LanceDB tables", id="load-tables", color="link", size="sm", className="mt-2"),
315
- dcc.Dropdown(id="db-tables-dropdown", placeholder="Select an existing table"),
316
- dbc.Button("Display Table", id="load-data-db", color="success", size="sm", className="mt-2"),
317
- dbc.Button("Drop Table", id="drop-data-db", color="danger", size="sm", className="mt-2"),
 
 
 
 
 
 
 
 
 
 
318
  ])
319
 
320
  return html.Div("Invalid tab selected.")
@@ -372,18 +382,6 @@ def load_item_sets(n_clicks, base_url):
372
  except Exception as e:
373
  return dash.no_update, dash.no_update
374
 
375
- ## -------------------- Load LanceDB tables callback--------------------
376
- @app.callback(
377
- Output("db-tables-dropdown", "options", allow_duplicate=True),
378
- Input("load-tables", "n_clicks"),
379
- prevent_initial_call=True
380
- )
381
- def list_tables(n_clicks):
382
- if not n_clicks:
383
- raise PreventUpdate
384
- tables = manager.list_tables()
385
- return [{"label": t, "value": t} for t in tables]
386
-
387
  ## -------------------- Load & Process Omeka items callback--------------------
388
  @app.callback(
389
  Output("umap-graph", "figure"),
@@ -457,7 +455,7 @@ def handle_omeka_data(n_clicks, item_set_id, client_config, table_name):
457
  Output("umap-graph", "figure", allow_duplicate=True),
458
  Output("status", "children", allow_duplicate=True),
459
  Input("load-data-db", "n_clicks"),
460
- State("db-tables-dropdown", "value"),
461
  prevent_initial_call=True
462
  )
463
  def handle_db_data(n_clicks, db_table):
@@ -500,7 +498,7 @@ def show_point_details(hoverData):
500
  Input("search-button", "n_clicks"),
501
  Input("search-limit-slider", "value"), # Add slider input
502
  State("search-input", "value"),
503
- State("db-tables-dropdown", "value"),
504
  State("umap-graph", "figure"),
505
  prevent_initial_call=True
506
  )
@@ -568,30 +566,27 @@ def clear_search(n_clicks, current_fig):
568
 
569
  return fig, "" # Return cleared figure and empty search input
570
 
571
- ## -------------------- Load LanceDB data callback--------------------
572
  @app.callback(
573
  Output("db-tables-dropdown", "options",allow_duplicate=True), # Update dropdown options
574
  Output("status", "children",allow_duplicate=True), # Show status message
575
- Output("db-tables-dropdown", "value",allow_duplicate=True), # Clear current selection
576
  Input("drop-data-db", "n_clicks"),
577
- State("db-tables-dropdown", "value"),
 
578
  prevent_initial_call=True
579
  )
580
- def drop_db_data(n_clicks, db_table):
581
  if not n_clicks or not db_table:
582
  raise PreventUpdate
583
 
584
  try:
585
- # Delete the table
586
  success = manager.drop_table(db_table)
587
 
588
  if success:
589
- # Get updated list of tables
590
- tables = manager.list_tables()
591
- options = [{"label": t, "value": t} for t in tables]
592
- return options, f"Table '{db_table}' successfully deleted", None
593
  else:
594
- return dash.no_update, f"Failed to delete table '{db_table}'", dash.no_update
595
 
596
  except Exception as e:
597
  print(f"Error dropping table: {str(e)}")
 
72
 
73
  # Tabs
74
  dcc.Tabs(id="data-tabs", value="api", children=[
75
+ dcc.Tab(label="Harvest data from Omeka S", value="omeka"),
76
+ dcc.Tab(label="Visualize existing collections", value="lance")
77
  ]),
78
 
79
  html.Div(id="data-tab-content"),
 
250
  if tab == "omeka":
251
  return html.Div([
252
  html.Div([
253
+ html.H5("Harvest data from an Omeka S instance", className="mb-3"),
254
  # API URL input with full width
255
  dbc.InputGroup([
256
  dbc.Input(
 
310
  ], className="border rounded bg-white shadow-sm")
311
  elif tab == "lance":
312
  return html.Div([
313
+ html.H5("Visualize existing collections already loaded"),
314
+ tables = manager.list_tables()
315
+ return html.Div([
316
+ html.H5("From LanceDB", className="mb-3"),
317
+ html.Div([
318
+ dbc.RadioItems(
319
+ id="db-tables-radio",
320
+ options=[{"label": t, "value": t} for t in tables],
321
+ value=tables[0] if tables else None,
322
+ className="mb-3"
323
+ ),
324
+ dbc.Button("Display Table", id="load-data-db", color="success", size="sm", className="me-2"),
325
+ dbc.Button("Drop Table", id="drop-data-db", color="danger", size="sm"),
326
+ ]) if tables else html.P("No tables available in LanceDB", className="text-muted"),
327
+ ], className="border rounded bg-white shadow-sm p-3")
328
  ])
329
 
330
  return html.Div("Invalid tab selected.")
 
382
  except Exception as e:
383
  return dash.no_update, dash.no_update
384
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  ## -------------------- Load & Process Omeka items callback--------------------
386
  @app.callback(
387
  Output("umap-graph", "figure"),
 
455
  Output("umap-graph", "figure", allow_duplicate=True),
456
  Output("status", "children", allow_duplicate=True),
457
  Input("load-data-db", "n_clicks"),
458
+ State("db-tables-radio", "value"),
459
  prevent_initial_call=True
460
  )
461
  def handle_db_data(n_clicks, db_table):
 
498
  Input("search-button", "n_clicks"),
499
  Input("search-limit-slider", "value"), # Add slider input
500
  State("search-input", "value"),
501
+ State("db-tables-radio", "value"),
502
  State("umap-graph", "figure"),
503
  prevent_initial_call=True
504
  )
 
566
 
567
  return fig, "" # Return cleared figure and empty search input
568
 
569
+ ## -------------------- Drop table callback--------------------
570
  @app.callback(
571
  Output("db-tables-dropdown", "options",allow_duplicate=True), # Update dropdown options
572
  Output("status", "children",allow_duplicate=True), # Show status message
 
573
  Input("drop-data-db", "n_clicks"),
574
+ State("db-tables-radio", "value"),
575
+ State("data-tabs", "value"),
576
  prevent_initial_call=True
577
  )
578
+ def drop_db_data(n_clicks, db_table, current_tab):
579
  if not n_clicks or not db_table:
580
  raise PreventUpdate
581
 
582
  try:
 
583
  success = manager.drop_table(db_table)
584
 
585
  if success:
586
+ # Re-render the entire tab content to show updated radio buttons
587
+ return render_tab_content("lance"), f"Table '{db_table}' successfully deleted"
 
 
588
  else:
589
+ return dash.no_update, f"Failed to delete table '{db_table}'"
590
 
591
  except Exception as e:
592
  print(f"Error dropping table: {str(e)}")