Skip to content

Commit

Permalink
update preview example
Browse files Browse the repository at this point in the history
Signed-off-by: Sajid Alam <[email protected]>
  • Loading branch information
SajidAlamQB committed Sep 3, 2024
1 parent e09ba1f commit c2c8b9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 17 additions & 9 deletions docs/source/preview_custom_datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 14 in docs/source/preview_custom_datasets.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/source/preview_custom_datasets.md#L14

[Kedro-viz.headings] 'TablePreview' should use sentence-style capitalization.
Raw output
{"message": "[Kedro-viz.headings] 'TablePreview' should use sentence-style capitalization.", "location": {"path": "docs/source/preview_custom_datasets.md", "range": {"start": {"line": 14, "column": 4}}}, "severity": "WARNING"}
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:

Expand All @@ -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
```


Expand Down
2 changes: 2 additions & 0 deletions docs/source/preview_datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```

0 comments on commit c2c8b9a

Please sign in to comment.