Skip to content

visu

plantimager.webui.visu Link

dash_boostrap_carousel(images, access_token)

Creates a Bootstrap Carousel component from a list of image URLs.

Parameters:

Name Type Description Default
images list[str]

A list of image URLs to include in the carousel.

required
access_token Optional[str]

AN access token used to authenticate against PlantDB.

required

Returns:

Type Description
Carousel

A Dash Bootstrap Components Carousel.

Notes

The image URLs are sorted alphabetically before being added to the carousel.

Source code in plantimager/webui/visu.py
 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 dash_boostrap_carousel(images: list[str], access_token: Optional[str]) -> Carousel:
    """
    Creates a Bootstrap Carousel component from a list of image URLs.

    Parameters
    ----------
    images
        A list of image URLs to include in the carousel.
    access_token : Optional[str]
        AN access token used to authenticate against PlantDB.

    Returns
    -------
    Carousel
        A Dash Bootstrap Components Carousel.

    Notes
    -----
    The image URLs are sorted alphabetically before being added to the carousel.
    """
    from plantimager.webui.utils import load_image_from_url

    images.sort()

    with ThreadPoolExecutor(max_workers=4) as pool:
        encoded_images = list(pool.map(lambda img: load_image_from_url(img, access_token), images))
    carousel = Carousel(
        items=[{"key": idx, "alt": img.split('/')[-1], "src": encoded_images[idx]} for idx, img in
               enumerate(images)],
        controls=True,
        indicators=True,
        slide=False,
        class_name="carousel-fade",
    )
    return carousel
plotly_image_carousel(images, height=900.0, width=900.0, title='Carousel', layout_kwargs=None)

An image carousel based on Plotly.

Parameters:

Name Type Description Default
images list[ImageLike]

The list of images to represent, each of which should be convertible into a numpy.ndarray.

required
height float

The height of the figure to create, in pixels. Defaults to 900.

900.0
width float

The width of the figure to create, in pixels. Defaults to 900.

900.0
title str

The title to give to the figure. Defaults to "Carousel".

'Carousel'
layout_kwargs dict[str, Any] | None

A dictionary to customize the figure layout. If provided, it will be merged with the default layout style.

None

Returns:

Type Description
Figure

The plotly figure to display.

See Also

plotly.graph_objects.Figure

References

Plotly documentation for Layout: https://plotly.com/python/reference/layout/

Source code in plantimager/webui/visu.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def plotly_image_carousel(
        images: list[ImageLike],
        height: float = 900.0,
        width: float = 900.0,
        title: str = "Carousel",
        layout_kwargs: Optional[LayoutDict] = None,
) -> Figure:
    """An image carousel based on Plotly.

    Parameters
    ----------
    images : list[ImageLike]
        The list of images to represent, each of which should be convertible into a ``numpy.ndarray``.
    height : float, optional
        The height of the figure to create, in pixels. Defaults to ``900``.
    width : float, optional
        The width of the figure to create, in pixels. Defaults to ``900``.
    title : str, optional
        The title to give to the figure. Defaults to ``"Carousel"``.
    layout_kwargs : dict[str, Any] | None, optional
        A dictionary to customize the figure layout. If provided, it will be merged with the
        default layout style.

    Returns
    -------
    plotly.graph_objects.Figure
        The plotly figure to display.

    See Also
    --------
    plotly.graph_objects.Figure

    References
    ----------
    Plotly documentation for `Layout`: https://plotly.com/python/reference/layout/
    """
    layout_style: LayoutDict = {
        "height": height,
        "width": width,
        "title": title,
        "showlegend": False,
        "xaxis": {"visible": False},
        "yaxis": {"visible": False},
    }
    if isinstance(layout_kwargs, dict):
        layout_style.update(layout_kwargs)

    array: np.ndarray = np.array([np.array(img) for img in images])
    fig: Figure = px.imshow(
        array,
        animation_frame=0,
        binary_string=True,
        labels=dict(animation_frame="Image"),
    )
    fig.update_layout(**layout_style)
    fig.update_scenes(aspectmode='data')

    return fig