From c2c8b9acd210010a9bf774fd950cbff042c9e6d9 Mon Sep 17 00:00:00 2001 From: Sajid Alam Date: Tue, 3 Sep 2024 12:43:37 +0100 Subject: [PATCH] update preview example Signed-off-by: Sajid Alam --- docs/source/preview_custom_datasets.md | 26 +++++++++++++++++--------- docs/source/preview_datasets.md | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/source/preview_custom_datasets.md b/docs/source/preview_custom_datasets.md index 99fc3f8c79..8defc11da8 100644 --- a/docs/source/preview_custom_datasets.md +++ b/docs/source/preview_custom_datasets.md @@ -11,7 +11,14 @@ PlotlyPreview = NewType("PlotlyPreview", dict) JSONPreview = NewType("JSONPreview", dict) ``` -Arbitrary arguments can be included in the `preview()` function, which can be later specified in the `catalog.yml` file. +## TablePreview +For `TablePreview`, the returned dictionary must contain the following keys: + +`index`: A list of row indices. +`columns`: A list of column names. +`data`: A list of rows, where each row is itself a list of values. + +Arbitrary arguments can be included in the `preview()` function, which can be later specified in the `catalog.yml` file. Ensure that these arguments (like `nrows`, `ncolumns`, and `filters`) match the structure of your dataset. Below is an example demonstrating how to implement the `preview()` function with user-specified arguments for a `CustomDataset` class that utilizes `TablePreview` to enable previewing tabular data on Kedro-Viz: @@ -36,15 +43,16 @@ from kedro_datasets._typing import TablePreview class CustomDataset: def preview(self, nrows, ncolumns, filters) -> TablePreview: - filtered_data = self.data + data = self.load() for column, value in filters.items(): - filtered_data = filtered_data[filtered_data[column] == value] - subset = filtered_data.iloc[:nrows, :ncolumns] - df_dict = {} - for column in subset.columns: - df_dict[column] = subset[column] - return df_dict - + data = data[data[column] == value] + subset = data.iloc[:nrows, :ncolumns] + preview_data = { + 'index': list(subset.index), # List of row indices + 'columns': list(subset.columns), # List of column names + 'data': subset.values.tolist() # List of rows, where each row is a list of values + } + return preview_data ``` diff --git a/docs/source/preview_datasets.md b/docs/source/preview_datasets.md index 474822e1f6..1d6b455e22 100644 --- a/docs/source/preview_datasets.md +++ b/docs/source/preview_datasets.md @@ -57,6 +57,8 @@ companies: preview: false ``` +You can also disable previews globally through the settings menu on Kedro-Viz. + ```{note} Starting from Kedro-Viz 9.2.0, previews are disabled by default for the CLI commands `kedro viz deploy` and `kedro viz build`. You can control this behavior using the `--include-previews` flag with these commands. For `kedro viz run`, previews are enabled by default and can be controlled from the publish modal dialog, refer to the [Publish and share](./share_kedro_viz) for more instructions. ``` \ No newline at end of file