Skip to content

table

plantimager.webui.pages.table Link

refresh_table_data Link

refresh_table_data(n_clicks, host, port, prefix)

Refresh the dataset dictionary.

Parameters:

Name Type Description Default
n_clicks int

The number of times the button has been clicked.

required
url str

The URL of the page.

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
Source code in plantimager/webui/pages/table.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
@callback(
    Output('dataset-dict', 'data', allow_duplicate=True),
    Output('refresh-table-button', 'n_clicks'),
    Input('refresh-table-button', 'n_clicks'),
    State('rest-api-host', 'data'),
    State('rest-api-port', 'data'),
    State('rest-api-prefix', 'data'),
    prevent_initial_call=True
)
def refresh_table_data(n_clicks, host, port, prefix):
    """Refresh the dataset dictionary.

    Parameters
    ----------
    n_clicks : int
        The number of times the button has been clicked.
    url : str
        The URL of the page.
    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.
    """
    if n_clicks > 0:
        dataset_dict = get_dataset_dict(host=host, port=port, prefix=prefix)
        return dataset_dict, 0
    return dash.no_update, 0
show_carousel_modal(cell_data)

Display a carousel modal dialog based on cell data from a plantdb-dag component.

This callback function manages the visibility and content of a carousel modal dialog that displays dataset information. It processes cell renderer data from a plantdb-dag component to extract dataset information and controls the modal's state.

Parameters:

Name Type Description Default
cell_data dict or None

Cell renderer data from the plantdb-dag component. Expected to contain a 'rowId' key with the dataset name. If None, the modal will be closed.

required

Returns:

Type Description
str or None

The name of the dataset to be displayed

bool

Boolean flag indicating whether the modal should be open (True) or closed (False)

str

The title to be displayed in the modal header

Source code in plantimager/webui/pages/table.py
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
@callback(
    Output("view-dataset", "data"),
    Output("carousel-modal", "is_open"),
    Output("carousel-modal-title", "children"),
    Input("plantdb-dag", "cellRendererData"),
)
def show_carousel_modal(cell_data):
    """
    Display a carousel modal dialog based on cell data from a plantdb-dag component.

    This callback function manages the visibility and content of a carousel modal
    dialog that displays dataset information. It processes cell renderer data
    from a plantdb-dag component to extract dataset information and controls
    the modal's state.

    Parameters
    ----------
    cell_data : dict or None
        Cell renderer data from the plantdb-dag component. Expected to contain
        a 'rowId' key with the dataset name. If None, the modal will be closed.

    Returns
    -------
    str or None
        The name of the dataset to be displayed
    bool
        Boolean flag indicating whether the modal should be open (True) or closed (False)
    str
        The title to be displayed in the modal header
    """
    if cell_data is None:
        return None, False, "Carousel"

    try:
        # If using row data, you can access it through:
        dataset_name = cell_data.get('rowId', None)
        return dataset_name, True, f"Carousel - {dataset_name}"
    except Exception as e:
        print(f"Error in show_carousel_modal: {e}")
        return None, False, "Carousel"

update_back_button_href Link

update_back_button_href(_)

Update the href of the back button.

Source code in plantimager/webui/pages/table.py
 96
 97
 98
 99
100
101
102
@callback(
    Output("back-button", "href"),
    Input('url', 'pathname')
)
def update_back_button_href(_):
    """Update the href of the back button."""
    return get_relative_path("/")

update_on_url_change Link

update_on_url_change(url, host, port, prefix)

Update the dataset dictionary when the URL changes.

Parameters:

Name Type Description Default
url str

The URL of the page.

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
Source code in plantimager/webui/pages/table.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
@callback(
    Output('dataset-dict', 'data'),
    Input('url', 'pathname'),
    State('rest-api-host', 'data'),
    State('rest-api-port', 'data'),
    State('rest-api-prefix', 'data')
)
def update_on_url_change(url, host, port, prefix):
    """Update the dataset dictionary when the URL changes.

    Parameters
    ----------
    url : str
        The URL of the page.
    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.
    """
    if url.endswith('/table'):
        return get_dataset_dict(host=host, port=port, prefix=prefix)
    return dash.no_update

update_table Link

update_table(dataset_dict, url, port, prefix)

Update the AG Grid table.

Parameters:

Name Type Description Default
dataset_dict dict

The currently stored dataset dictionary.

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
AgGrid

The AG Grid to display.

Source code in plantimager/webui/pages/table.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
@callback(Output('dataset-table', 'children'),
          Input('dataset-dict', 'data'),
          State('rest-api-host', 'data'),
          State('rest-api-port', 'data'),
          State('rest-api-prefix', 'data'))
def update_table(dataset_dict, url, port, prefix):
    """Update the AG Grid table.

    Parameters
    ----------
    dataset_dict : dict
        The currently stored dataset dictionary.
    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_ag_grid.AgGrid
        The AG Grid to display.
    """
    thumb_size = 150  # max width or height
    if dataset_dict is not None:
        table_dict = {col: [] for col in ["Thumbnail", "Name", "Action", "Date", "Species", "Images"]}
        plantdb_url = base_url(url, port, prefix)

        for ds_id, md in dataset_dict.items():
            thumbnail_url = md["thumbnailUri"].replace('thumb', f'{thumb_size}')
            # Include the first image thumbnail and a link to the carousel
            table_dict["Thumbnail"].append(f"![{ds_id}]({plantdb_url}{thumbnail_url})")
            table_dict["Name"].append(ds_id)
            table_dict["Action"].append("Open")
            table_dict["Date"].append(md["metadata"]["date"])
            table_dict["Species"].append(md["metadata"]["species"])
            table_dict["Images"].append(md["metadata"]["nbPhotos"])

        df = pd.DataFrame().from_dict(table_dict)
        table = dag.AgGrid(
            id="plantdb-dag",
            rowData=df.to_dict("records"),
            columnDefs=[_column_defs(col) for col in df.columns],
            getRowId="params.data.Name",
            dashGridOptions={
                "rowHeight": 120,
                "animateRows": False,
                "pagination": True,
                "paginationAutoPageSize": True,
            },
            persistence=True,
            persisted_props=["filterModel"],
            columnSize="autoSize",
            style={"margin": "auto auto", "height": "80vh"},
        )
    else:
        table = "No dataset loaded yet!"
    return table