Skip to content

carousel

plantimager.webui.carousel Link

images_carousel(open_modal, image_task, dataset_id, host, port, prefix)

Create a Dash carousel component displaying images from a specified dataset task.

This callback function generates a Bootstrap-styled carousel component for displaying images associated with a specific task in a dataset. The carousel is only generated when the modal is open and a valid dataset ID is provided.

Parameters:

Name Type Description Default
open_modal bool

Flag indicating whether the carousel modal is open

required
image_task str

Name of the image processing task to display images from

required
dataset_id str

Identifier of the dataset to retrieve images from

required
host str

The hostname or IP address of the PlantDB REST API server.

required
port int

The port number of the PlantDB REST API server.

required
prefix str

The prefix of the PlantDB REST API server.

required

Returns:

Type Description
Carousel or None

A Bootstrap carousel component containing the task images if conditions are met, None if the modal is closed or dataset_id is invalid

Source code in plantimager/webui/carousel.py
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 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
@callback(Output('carousel', 'children'),
          # Output('carousel', 'figure'),
          Input("carousel-modal", "is_open"),
          Input("select-image-task", "value"),
          State('view-dataset', 'data'),
          State('rest-api-host', 'data'),
          State('rest-api-port', 'data'),
          State('rest-api-prefix', 'data'),
          )
def images_carousel(open_modal, image_task, dataset_id, host, port, prefix):
    """Create a Dash carousel component displaying images from a specified dataset task.

    This callback function generates a Bootstrap-styled carousel component for displaying
    images associated with a specific task in a dataset. The carousel is only generated
    when the modal is open and a valid dataset ID is provided.

    Parameters
    ----------
    open_modal : bool
        Flag indicating whether the carousel modal is open
    image_task : str
        Name of the image processing task to display images from
    dataset_id : str
        Identifier of the dataset to retrieve images from
    host : str
       The hostname or IP address of the PlantDB REST API server.
    port : int
        The port number of the PlantDB REST API server.
    prefix : str
        The prefix of the PlantDB REST API server.

    Returns
    -------
    dash_bootstrap_components.Carousel or None
        A Bootstrap carousel component containing the task images if conditions are met,
        None if the modal is closed or dataset_id is invalid
    """
    if not open_modal or dataset_id is None or dataset_id == '':
        return None

    images = list_task_images_uri(dataset_id, task_name=image_task, size='orig', host=host, port=port, prefix=prefix)

    # fig_layout_kwargs = {'font_family': FONT_FAMILY, 'paper_bgcolor': "#F3F3F3",
    #                      'autosize': True, 'margin': {'t': 25, 'b': 5}, 'width': None, 'height': None}
    # fig = plotly_image_carousel(images, title=dataset_id, layout_kwargs=fig_layout_kwargs)
    # fig.update_layout(uirevision='value')
    # # Remove the axis ticks and labels:
    # fig.update_layout(xaxis={'visible': False}, yaxis={'visible': False})
    # return fig
    return dash_boostrap_carousel(images)

update_image_task_dropdown Link

update_image_task_dropdown(open_modal, dataset_id, host, port, prefix)

Updates the dropdown options for image tasks based on the dataset and API configuration.

This callback function is triggered when the carousel modal is opened or closed. It fetches the available tasks for a given dataset from the API and filters them against predefined IMAGE_TASKS to provide relevant options for the dropdown.

Parameters:

Name Type Description Default
open_modal bool

State of the carousel modal (True if open, False if closed).

required
dataset_id str or None

Identifier of the selected dataset. Can be None or empty string if no dataset is selected.

required
host str

The hostname or IP address of the PlantDB REST API server.

required
port int

The port number of the PlantDB REST API server.

required
prefix str

The prefix of the PlantDB REST API server.

required

Returns:

Type Description
list of str

List of available image task options. Returns ['images'] if the modal is closed or no dataset is selected. Otherwise returns the intersection of IMAGE_TASKS and the tasks available for the selected dataset.

Source code in plantimager/webui/carousel.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@callback(
    Output('select-image-task', 'options'),
    Input("carousel-modal", "is_open"),
    State('view-dataset', 'data'),
    State('rest-api-host', 'data'),
    State('rest-api-port', 'data'),
    State('rest-api-prefix', 'data'),
)
def update_image_task_dropdown(open_modal, dataset_id, host, port, prefix):
    """Updates the dropdown options for image tasks based on the dataset and API configuration.

    This callback function is triggered when the carousel modal is opened or closed. It fetches
    the available tasks for a given dataset from the API and filters them against predefined
    IMAGE_TASKS to provide relevant options for the dropdown.

    Parameters
    ----------
    open_modal : bool
        State of the carousel modal (True if open, False if closed).
    dataset_id : str or None
        Identifier of the selected dataset. Can be None or empty string if no dataset is selected.
    host : str
       The hostname or IP address of the PlantDB REST API server.
    port : int
        The port number of the PlantDB REST API server.
    prefix : str
        The prefix of the PlantDB REST API server.

    Returns
    -------
    list of str
        List of available image task options. Returns ['images'] if the modal is closed
        or no dataset is selected. Otherwise returns the intersection of IMAGE_TASKS and
        the tasks available for the selected dataset.

    """
    if not open_modal or dataset_id is None or dataset_id == '':
        return ['images']
    tasks_fileset = get_tasks_fileset_from_api(dataset_id, host=host, port=port, prefix=prefix)
    return [task for task in IMAGE_TASKS if task in tasks_fileset]