Skip to content

config

plantimager.webui.config Link

PlantDB Configuration Interface for Plant Imager Web UI.

This module provides components and callbacks for configuring the connection to the PlantDB API and managing datasets within the Plant Imager web interface.

Key Features
  • PlantDB API connection configuration and testing
  • Dataset listing and management
  • Dynamic UI components for database status visualization
  • Bootstrap-styled modals and alerts for user interaction

check_server_availability Link

check_server_availability(_, host, port, prefix, ssl, stored_host, stored_port, stored_prefix, stored_ssl)

Checks the availability of a server based on the provided host and port and updates the UI accordingly.

Parameters:

Name Type Description Default
_ int

The n_clicks property of the load-plantdb-button element, which triggers the callback (not used).

required
host str

The IP address or hostname of the server to test.

required
port int

The port number of the server to test.

required
prefix str

The URL prefix of the server to test.

required
ssl bool

Flag indicating whether SSL (HTTPS) is enabled.

required
stored_host str

The previously stored server host value, used if the connection test fails.

required
stored_port int

The previously stored server port value, used if the connection test fails.

required
stored_prefix str

The previously stored server prefix value, used if the connection test fails.

required
stored_ssl bool

The previously stored server SSL flag, used if the connection test fails.

required

Returns:

Type Description
bool

A storer flag indicating whether the connection test was successful.

bool

A boolean indicating whether the load button should be disabled.

str

The updated server host value to store.

int

The updated server port value to store.

str

The updated server prefix value to store.

bool

The updated server SSL flag value to store.

Source code in plantimager/webui/config.py
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
@callback(
    Output('connected', 'data'),
    Output('load-plantdb-button', 'disabled'),
    Output('rest-api-host', 'data'),
    Output('rest-api-port', 'data'),
    Output('rest-api-prefix', 'data'),
    Output('rest-api-ssl', 'data'),
    Input('connect-plantdb-button', 'n_clicks'),
    State('api-address', 'value'),
    State('api-port', 'value'),
    State('api-prefix', 'value'),
    State('api-ssl', 'value'),
    State('rest-api-host', 'data'),
    State('rest-api-port', 'data'),
    State('rest-api-prefix', 'data'),
    State('rest-api-ssl', 'data'),
)
def check_server_availability(
        _: int,
        host: str | None,
        port: int | str | None,
        prefix: str | None,
        ssl: bool | None,
        stored_host: str | None,
        stored_port: int | str | None,
        stored_prefix: str | None,
        stored_ssl: bool | None,
) -> tuple[bool, bool, str, int | str, str, bool]:
    """Checks the availability of a server based on the provided host and port and updates the UI accordingly.

    Parameters
    ----------
    _ : int
        The n_clicks property of the load-plantdb-button element, which triggers the callback (not used).
    host : str
        The IP address or hostname of the server to test.
    port : int
        The port number of the server to test.
    prefix : str
        The URL prefix of the server to test.
    ssl : bool
        Flag indicating whether SSL (HTTPS) is enabled.
    stored_host : str
        The previously stored server host value, used if the connection test fails.
    stored_port : int
        The previously stored server port value, used if the connection test fails.
    stored_prefix : str
        The previously stored server prefix value, used if the connection test fails.
    stored_ssl : bool
        The previously stored server SSL flag, used if the connection test fails.

    Returns
    -------
    bool
        A storer flag indicating whether the connection test was successful.
    bool
        A boolean indicating whether the load button should be disabled.
    str
        The updated server host value to store.
    int
        The updated server port value to store.
    str
        The updated server prefix value to store.
    bool
        The updated server SSL flag value to store.
    """
    if host is None:
        host = stored_host
    if port is None:
        port = stored_port
    if prefix is None:
        prefix = stored_prefix
    if ssl is None:
        ssl = stored_ssl

    # Handle URLs that include a protocol prefix
    if host and isinstance(host, str):
        if host.startswith("http://"):
            host = host[7:]
            ssl = False
        elif host.startswith("https://"):
            host = host[8:]
            ssl = True

    try:
        allow_private_ip = os.environ.get('ALLOW_PRIVATE_IP', 'false').lower() == 'true'
        cert_path = os.environ.get('CERT_PATH', None)
        url = plantdb_url(host, port=port, prefix=prefix, ssl=ssl)
        print("-------------------------------------------------------")
        print("URL:", url)
        availability = is_server_available(url, allow_private_ip=allow_private_ip, cert_path=cert_path)
        print("availability.ok:", availability.ok)
        print("availability.status_code:", availability.status_code)
        print("availability.message:", availability.message)
        print("availability.url:", availability.url)
        print("availability.final_url:", availability.final_url)
        print("-------------------------------------------------------")
    except:
        is_available = False
    else:
        is_available = availability.ok

    if is_available:
        return True, False, host, port, prefix, ssl
    else:
        return False, True, host, port, prefix, ssl

create_dataset_cfg_icon Link

create_dataset_cfg_icon(is_connected=False, dataset_list=None)

Create a navigation link with the database status icon and dataset counter badge.

Creates a Bootstrap NavLink component that displays a database status icon and a badge showing the number of datasets. The icon changes appearance based on connection status.

Parameters:

Name Type Description Default
is_connected bool

Flag indicating whether the database connection is established, by default False

False
dataset_list list

List of datasets to count, by default empty list

None

Returns:

Type Description
NavLink

A navigation link component containing: - Database status icon - Badge showing dataset count The NavLink is styled and positioned according to the application's design.

Source code in plantimager/webui/config.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def create_dataset_cfg_icon(is_connected: bool = False, dataset_list: list | None = None) -> dbc.NavLink:
    """Create a navigation link with the database status icon and dataset counter badge.

    Creates a Bootstrap NavLink component that displays a database status icon and
    a badge showing the number of datasets. The icon changes appearance based on
    connection status.

    Parameters
    ----------
    is_connected : bool, optional
        Flag indicating whether the database connection is established,
        by default False
    dataset_list : list, optional
        List of datasets to count, by default empty list

    Returns
    -------
    dash.bootstrap_components.NavLink
        A navigation link component containing:
        - Database status icon
        - Badge showing dataset count
        The NavLink is styled and positioned according to the application's design.
    """
    if dataset_list is None:
        dataset_list = []
    return dbc.NavLink(
        children=[
            dataset_cfg_status(is_connected),
            dbc.Badge(
                children=f"{len(dataset_list)}",
                id="dataset-count-badge",
                color="primary",
                className="position-absolute top-45 start-100 translate-middle",
                pill=True
            )
        ],
        id='plantdb-cfg-button',
        n_clicks=0,
        className="position-relative align-left",
        style={'color': "#f3f3f3"},
    )

dataset_cfg_status Link

dataset_cfg_status(is_connected)

Generate a database status icon based on the connection state.

Creates a Bootstrap icon element representing the database connection status. Returns a check icon when connected and a gear icon when disconnected.

Parameters:

Name Type Description Default
is_connected bool

Flag indicating whether the database connection is established.

required

Returns:

Type Description
I

A Bootstrap icon component with the appropriate class based on connection status.

Source code in plantimager/webui/config.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def dataset_cfg_status(is_connected: bool) -> html.I:
    """Generate a database status icon based on the connection state.

    Creates a Bootstrap icon element representing the database connection status.
    Returns a check icon when connected and a gear icon when disconnected.

    Parameters
    ----------
    is_connected : bool
        Flag indicating whether the database connection is established.

    Returns
    -------
    dash.html.I
        A Bootstrap icon component with the appropriate class based on connection status.
    """
    if is_connected:
        return html.I(className="bi bi-database-check fs-3")
    else:
        return html.I(className="bi bi-database-gear fs-3")

show_api_address Link

show_api_address(modal_is_open, stored_host)

Callback updating the value of the 'api-address' field with stored data when opening the PlantDB configuration modal.

Parameters:

Name Type Description Default
modal_is_open bool

Indicates whether the configuration modal is currently open.

required
stored_host str or None

The stored value of the PlantDB API host. Can be None if not previously set.

required

Returns:

Type Description
str

The IP address to be used, either the stored host value or the PLANTDB_API_HOST constant.

Source code in plantimager/webui/config.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@callback(
    Output("api-address", "value"),
    Input("plantdb-cfg-modal", "is_open"),
    State("rest-api-host", "data")
)
def show_api_address(modal_is_open: bool, stored_host: str | None) -> str:
    """Callback updating the value of the 'api-address' field with stored data when opening the PlantDB configuration modal.

    Parameters
    ----------
    modal_is_open : bool
        Indicates whether the configuration modal is currently open.
    stored_host : str or None
        The stored value of the PlantDB API host. Can be ``None`` if not previously set.

    Returns
    -------
    str
        The IP address to be used, either the stored host value or the ``PLANTDB_API_HOST`` constant.
    """
    if modal_is_open:
        return stored_host if stored_host is not None else PLANTDB_API_HOST
    else:
        return stored_host

show_api_port Link

show_api_port(modal_is_open, stored_port)

Callback updating the value of the 'api-port' field with stored data when opening the PlantDB configuration modal.

Parameters:

Name Type Description Default
modal_is_open bool

Boolean indicating whether the configuration modal is open or closed.

required
stored_port str or None

Stored port value retrieved from the state. Can be None if not specified.

required

Returns:

Type Description
str

Value to be set for the "api-port" input field, either the stored port value or the PLANTDB_API_PORT constant.

Source code in plantimager/webui/config.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
@callback(
    Output("api-port", "value"),
    Input("plantdb-cfg-modal", "is_open"),
    State("rest-api-port", "data")
)
def show_api_port(modal_is_open: bool, stored_port: int | None) -> int | str:
    """Callback updating the value of the 'api-port' field with stored data when opening the PlantDB configuration modal.

    Parameters
    ----------
    modal_is_open : bool
        Boolean indicating whether the configuration modal is open or closed.
    stored_port : str or None
        Stored port value retrieved from the state. Can be ``None`` if not specified.

    Returns
    -------
    str
        Value to be set for the "api-port" input field, either the stored port value or the ``PLANTDB_API_PORT`` constant.
    """
    if modal_is_open:
        return stored_port if stored_port is not None else PLANTDB_API_PORT
    else:
        return stored_port

show_api_prefix Link

show_api_prefix(modal_is_open, stored_prefix)

Callback updating the value of the 'api-prefix' field with stored data when opening the PlantDB configuration modal.

Parameters:

Name Type Description Default
modal_is_open bool

Boolean indicating whether the configuration modal is open or closed.

required
stored_prefix str or None

Stored prefix value retrieved from the state. Can be None if not specified.

required

Returns:

Type Description
str

Value to be set for the "api-prefix" input field.

Source code in plantimager/webui/config.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
@callback(
    Output("api-prefix", "value"),
    Input("plantdb-cfg-modal", "is_open"),
    State("rest-api-prefix", "data")
)
def show_api_prefix(modal_is_open: bool, stored_prefix: str | None) -> int | str:
    """Callback updating the value of the 'api-prefix' field with stored data when opening the PlantDB configuration modal.

    Parameters
    ----------
    modal_is_open : bool
        Boolean indicating whether the configuration modal is open or closed.
    stored_prefix : str or None
        Stored prefix value retrieved from the state. Can be ``None`` if not specified.

    Returns
    -------
    str
        Value to be set for the "api-prefix" input field.
    """
    if modal_is_open:
        return stored_prefix if stored_prefix is not None else ""
    else:
        return stored_prefix

show_api_ssl Link

show_api_ssl(modal_is_open, stored_ssl)

Callback updating the value of the 'api-ssl' checkbox with stored data when opening the PlantDB configuration modal.

Parameters:

Name Type Description Default
modal_is_open bool

Boolean indicating whether the configuration modal is open or closed.

required
stored_ssl bool or None

Stored SSL flag retrieved from the state. Can be None if not specified.

required

Returns:

Type Description
bool

Value to be set for the "api-ssl" checkbox.

Source code in plantimager/webui/config.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
@callback(
    Output("api-ssl", "value"),
    Input("plantdb-cfg-modal", "is_open"),
    State("rest-api-ssl", "data")
)
def show_api_ssl(modal_is_open: bool, stored_ssl: bool | None) -> bool:
    """Callback updating the value of the 'api-ssl' checkbox with stored data when opening the PlantDB configuration modal.

    Parameters
    ----------
    modal_is_open : bool
        Boolean indicating whether the configuration modal is open or closed.
    stored_ssl : bool or None
        Stored SSL flag retrieved from the state. Can be ``None`` if not specified.

    Returns
    -------
    bool
        Value to be set for the "api-ssl" checkbox.
    """
    if modal_is_open:
        return stored_ssl if stored_ssl is not None else False
    else:
        return stored_ssl

show_plantdb_status Link

show_plantdb_status(status, host, port, prefix, ssl)

Display the connection status of the PlantDB server in a Bootstrap alert component.

This callback function generates a styled alert component that shows whether the PlantDB server is available or not. The alert includes an icon and descriptive text with the server's host and port information when applicable.

Parameters:

Name Type Description Default
status bool or None

Connection status of the PlantDB server: - None: status unknown - True: server is available - False: server is unavailable

required
host str

Hostname or IP address of the PlantDB server

required
port int

Port number of the PlantDB server

required
prefix str

URL prefix of the PlantDB server

required
ssl bool

Flag indicating whether SSL (HTTPS) is enabled

required

Returns:

Type Description
Alert

A Bootstrap alert component with the appropriate styling and message based on the connection status: - Info (blue): when status is unknown - Success (green): when server is available - Danger (red): when server is unavailable

Source code in plantimager/webui/config.py
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
@callback(
    Output("plantdb-status-form", "children"),
    Input("connected", "data"),
    State("rest-api-host", "data"),
    State("rest-api-port", "data"),
    State("rest-api-prefix", "data"),
    State("rest-api-ssl", "data"),
)
def show_plantdb_status(status: bool | None, host: str, port: int, prefix: str, ssl: bool) -> dbc.Alert:
    """Display the connection status of the PlantDB server in a Bootstrap alert component.

    This callback function generates a styled alert component that shows whether the
    PlantDB server is available or not. The alert includes an icon and descriptive text
    with the server's host and port information when applicable.

    Parameters
    ----------
    status : bool or None
        Connection status of the PlantDB server:
        - ``None``: status unknown
        - ``True``: server is available
        - ``False``: server is unavailable
    host : str
        Hostname or IP address of the PlantDB server
    port : int
        Port number of the PlantDB server
    prefix : str
        URL prefix of the PlantDB server
    ssl : bool
        Flag indicating whether SSL (HTTPS) is enabled

    Returns
    -------
    dash_bootstrap_components.Alert
        A Bootstrap alert component with the appropriate styling and message based on
        the connection status:
        - Info (blue): when status is unknown
        - Success (green): when server is available
        - Danger (red): when server is unavailable
    """
    if status is None:
        status_form = dbc.Alert(children=[
            html.I(className="bi bi-info-circle-fill me-2"),
            "Unknown server availability."
        ], color="info")
    elif status:
        status_form = dbc.Alert(children=[
            html.I(className="bi bi-check-circle-fill me-2"),
            f"Server {plantdb_url(host, port=port, prefix=prefix, ssl=ssl)} available.",
        ], color="success")
    else:
        status_form = dbc.Alert(children=[
            html.I(className="bi bi-x-octagon-fill me-2"),
            f"Server {plantdb_url(host, port=port, prefix=prefix, ssl=ssl)} unavailable!",
        ], color="danger")
    return status_form

toggle_plantdb_cfg_modal Link

toggle_plantdb_cfg_modal(cfg_clicks, connect_clicks, host, port, prefix, ssl, is_open)

Toggle the visibility state of the PlantDB configuration modal.

This callback function controls the opening and closing of the PlantDB configuration modal dialog. It is triggered by clicking on either: 1. The configuration button (opens modal) 2. The connect button (closes modal only if connection successful)

Parameters:

Name Type Description Default
cfg_clicks int

Number of times the plantdb-cfg-button has been clicked.

required
connect_clicks int

Number of times the connect-plantdb-button has been clicked.

required
host str or None

The host value from the form.

required
port int or str or None

The port value from the form.

required
prefix str or None

The prefix value from the form.

required
ssl bool or None

The SSL flag from the form.

required
is_open bool

Current visibility state of the modal.

required

Returns:

Type Description
bool or None

The new visibility state of the modal.

Source code in plantimager/webui/config.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
@callback(Output("plantdb-cfg-modal", "is_open"),
          Input('plantdb-cfg-button', 'n_clicks'),
          Input('connect-plantdb-button', 'n_clicks'),
          State('api-address', 'value'),
          State('api-port', 'value'),
          State('api-prefix', 'value'),
          State('api-ssl', 'value'),
          State('plantdb-cfg-modal', 'is_open'),
          prevent_initial_call=True)
def toggle_plantdb_cfg_modal(
        cfg_clicks: int,
        connect_clicks: int,
        host: str | None,
        port: int | str | None,
        prefix: str | None,
        ssl: bool | None,
        is_open: bool
) -> bool | None:
    """Toggle the visibility state of the PlantDB configuration modal.

    This callback function controls the opening and closing of the PlantDB configuration
    modal dialog. It is triggered by clicking on either:
    1. The configuration button (opens modal)
    2. The connect button (closes modal only if connection successful)

    Parameters
    ----------
    cfg_clicks : int
        Number of times the plantdb-cfg-button has been clicked.
    connect_clicks : int
        Number of times the connect-plantdb-button has been clicked.
    host : str or None
        The host value from the form.
    port : int or str or None
        The port value from the form.
    prefix : str or None
        The prefix value from the form.
    ssl : bool or None
        The SSL flag from the form.
    is_open : bool
        Current visibility state of the modal.

    Returns
    -------
    bool or None
        The new visibility state of the modal.
    """
    # Identify which button was clicked using context
    triggered_id = ctx.triggered_id

    # The configuration button was clicked - open modal
    if triggered_id == 'plantdb-cfg-button':
        return True

    # The connect button was clicked - check the connection before closing
    elif triggered_id == 'connect-plantdb-button':
        # Only attempt to close if the modal is open
        if is_open:
            try:
                allow_private_ip = os.environ.get('ALLOW_PRIVATE_IP', 'false').lower() == 'true'
                availability = is_server_available(plantdb_url(host, port=port, prefix=prefix, ssl=ssl),
                                                   allow_private_ip=allow_private_ip,
                                                   cert_path=os.environ.get('CERT_PATH', None))
            except:
                # Keep modal open if connection fails
                return True
            else:
                # Close the modal only if the connection is successful
                return not availability.ok

    # Return no_update if no relevant button was clicked
    return no_update

update_dataset_badge Link

update_dataset_badge(dataset_list)

Update the dataset count badge with the current number of datasets.

This callback function updates a badge element in the UI to display the total number of datasets currently available in the system. It converts the length of the dataset list to a string for display.

Parameters:

Name Type Description Default
dataset_list list

A list containing the dataset names stored in the dcc.Store component.

required

Returns:

Type Description
str

String representation of the number of datasets in the list.

Source code in plantimager/webui/config.py
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
@callback(
    Output("dataset-count-badge", "children"),
    Input("dataset-list", "data")  # Assuming you have a dataset list stored in dcc.Store
)
def update_dataset_badge(dataset_list: list) -> str:
    """Update the dataset count badge with the current number of datasets.

    This callback function updates a badge element in the UI to display the total
    number of datasets currently available in the system. It converts the length
    of the dataset list to a string for display.

    Parameters
    ----------
    dataset_list : list
        A list containing the dataset names stored in the dcc.Store component.

    Returns
    -------
    str
        String representation of the number of datasets in the list.
    """
    return str(len(dataset_list))

update_dataset_list Link

update_dataset_list(n_clicks, connected, host, port, prefix, ssl)

Callback updating the dataset list and displaying the load status when a user clicks the load button.

Parameters:

Name Type Description Default
n_clicks int

The n_clicks property of the load-plantdb-button element, which triggers the callback (not used).

required
connected bool

The connection status of the PlantDB API server.

required
host str

The hostname or IP address of the PlantDB API server.

required
port int

The port number of the PlantDB API server.

required
prefix str

The prefix of the PlantDB API server.

required
ssl bool

Flag indicating whether SSL (HTTPS) is enabled.

required

Returns:

Type Description
Alert

An alert component indicating success or failure of dataset retrieval.

list of str

A list of dataset names retrieved from the server.

Source code in plantimager/webui/config.py
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
@callback(
    Output('load-status-form', 'children'),
    Output('dataset-list', 'data'),
    Input('load-plantdb-button', 'n_clicks'),
    Input('connected', 'data'),
    State('rest-api-host', 'data'),
    State('rest-api-port', 'data'),
    State('rest-api-prefix', 'data'),
    State('rest-api-ssl', 'data'),
    prevent_initial_call=True,
)
def update_dataset_list(
        n_clicks: int,
        connected: bool | None,
        host: str,
        port: int | str,
        prefix: str,
        ssl: bool,
) -> tuple[dbc.Alert, list[str]]:
    """Callback updating the dataset list and displaying the load status when a user clicks the load button.

    Parameters
    ----------
    n_clicks : int
        The n_clicks property of the load-plantdb-button element, which triggers the callback (not used).
    connected : bool
        The connection status of the PlantDB API server.
    host : str
       The hostname or IP address of the PlantDB API server.
    port : int
        The port number of the PlantDB API server.
    prefix : str
        The prefix of the PlantDB API server.
    ssl : bool
        Flag indicating whether SSL (HTTPS) is enabled.

    Returns
    -------
    dash_bootstrap_components.Alert
        An alert component indicating success or failure of dataset retrieval.
    list of str
        A list of dataset names retrieved from the server.
    """
    error = ""
    if not connected:
        error = "PlantDB API server not connected."
        return _unconnected_status(error=error), []

    try:
        dataset_list = request_scan_names_list(host, port=port, prefix=prefix, ssl=ssl,
                                       cert_path=os.environ.get('CERT_PATH', None))
    except RequestException as e:
        dataset_list = []
        error = e

    if dataset_list:
        status = _connected_status(dataset_list)
    else:
        status = _unconnected_status(error=error)

    return status, dataset_list

update_plantdb_cfg_button Link

update_plantdb_cfg_button(status, dataset_list)

Update the PlantDB configuration button's appearance based on connection status.

This callback function updates the visual representation of the PlantDB configuration button in the navigation bar depending on the connection status and dataset list state. It uses the create_dataset_cfg_icon function to generate the appropriate icon.

Parameters:

Name Type Description Default
status bool or None

The connection status to the PlantDB API. None indicates no connection attempt has been made. True indicates a successful connection. False indicates a failed connection.

required
dataset_list list or None

List of available datasets from the PlantDB. None if no datasets are loaded or connection is not established.

required

Returns:

Type Description
Component

A Dash HTML component representing the configuration button icon with the appropriate styling based on the connection status.

Source code in plantimager/webui/config.py
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
@callback(
    Output("plantdb-cfg-button", "children"),
    Input("connected", "data"),
    State("dataset-list", "data"),
)
def update_plantdb_cfg_button(status: bool | None, dataset_list: list | None) -> list:
    """Update the PlantDB configuration button's appearance based on connection status.

    This callback function updates the visual representation of the PlantDB configuration
    button in the navigation bar depending on the connection status and dataset list state.
    It uses the create_dataset_cfg_icon function to generate the appropriate icon.

    Parameters
    ----------
    status : bool or None
        The connection status to the PlantDB API.
        ``None`` indicates no connection attempt has been made.
        ``True`` indicates a successful connection.
        ``False`` indicates a failed connection.
    dataset_list : list or None
        List of available datasets from the PlantDB.
        ``None`` if no datasets are loaded or connection is not established.

    Returns
    -------
    dash.html.Component
        A Dash HTML component representing the configuration button icon
        with the appropriate styling based on the connection status.
    """
    return create_dataset_cfg_icon(status, dataset_list)