Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

show warning with button for chart builder if >50k rows or >50 cols (#7164)

Shahmir Varqha390b74ce78e1
diff --git a/frontend/src/components/data-table/charts/charts.tsx b/frontend/src/components/data-table/charts/charts.tsx
index 2caa6f12b9..c193e16afe 100644
--- a/frontend/src/components/data-table/charts/charts.tsx
+++ b/frontend/src/components/data-table/charts/charts.tsx
@@ -3,6 +3,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useAtom } from "jotai";
import {
+ AlertTriangle,
ChartColumnIcon,
ChevronLeftIcon,
ChevronRightIcon,
@@ -16,6 +17,7 @@ import React, { useMemo, useState } from "react";
import { type UseFormReturn, useForm } from "react-hook-form";
import useResizeObserver from "use-resize-observer";
import { PythonIcon } from "@/components/editor/cell/code/icons";
+import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Form } from "@/components/ui/form";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
@@ -26,7 +28,11 @@ import type { GetDataUrl } from "@/plugins/impl/DataTablePlugin";
import { vegaLoadData } from "@/plugins/impl/vega/loader";
import { useTheme } from "@/theme/useTheme";
import { inferFieldTypes } from "../columns";
-import type { FieldTypesWithExternalType } from "../types";
+import {
+ type FieldTypesWithExternalType,
+ TOO_MANY_ROWS,
+ type TooManyRows,
+} from "../types";
import { generateAltairChartSnippet } from "./chart-spec/altair-generator";
import { createSpecWithoutData } from "./chart-spec/spec";
import { ChartTypeSelect } from "./components/chart-items";
@@ -45,11 +51,15 @@ import { ChartType } from "./types";
const NEW_CHART_TYPE = "bar" as ChartType;
const DEFAULT_TAB_NAME = "table" as TabName;
const CHART_HEIGHT = 290;
+const CHART_MAX_ROWS = 50_000;
+const CHART_MAX_COLUMNS = 50;
export interface TablePanelProps {
cellId: CellId | null;
data: unknown[];
dataTable: JSX.Element;
+ totalRows: number | TooManyRows;
+ columns: number;
displayHeader: boolean;
getDataUrl?: GetDataUrl;
fieldTypes?: FieldTypesWithExternalType | null;
@@ -59,6 +69,8 @@ export const TablePanel: React.FC<TablePanelProps> = ({
cellId,
data,
dataTable,
+ totalRows,
+ columns,
getDataUrl,
fieldTypes,
displayHeader,
@@ -159,6 +171,11 @@ export const TablePanel: React.FC<TablePanelProps> = ({
setSelectedTab(newTabs[tabIndex].tabName);
};
+ const isLargeDataset =
+ totalRows === TOO_MANY_ROWS ||
+ totalRows > CHART_MAX_ROWS ||
+ columns > CHART_MAX_COLUMNS;
+
return (
<Tabs value={selectedTab} className="-mt-1">
<TabsList>
@@ -220,6 +237,7 @@ export const TablePanel: React.FC<TablePanelProps> = ({
saveChartType={saveChartType}
getDataUrl={getDataUrl}
fieldTypes={fieldTypes ?? inferFieldTypes(dataTable.props.data)}
+ isLargeDataset={isLargeDataset}
/>
</TabsContent>
);
@@ -238,6 +256,7 @@ export const ChartPanel: React.FC<{
saveChartType: (chartType: ChartType) => void;
getDataUrl?: GetDataUrl;
fieldTypes?: FieldTypesWithExternalType | null;
+ isLargeDataset: boolean;
}> = ({
tableData,
chartConfig,
@@ -246,6 +265,7 @@ export const ChartPanel: React.FC<{
saveChartType,
getDataUrl,
fieldTypes,
+ isLargeDataset,
}) => {
const { theme } = useTheme();
const form = useForm<ChartSchemaType>({
@@ -257,10 +277,12 @@ export const ChartPanel: React.FC<{
useState<ChartType>(chartType);
const [formCollapsed, setFormCollapsed] = useState(false);
+ const [renderLargeCharts, setRenderLargeCharts] = useState(!isLargeDataset);
+
const { ref: chartContainerRef } = useResizeObserver();
const { data, isPending, error } = useAsyncData(async () => {
- if (!getDataUrl || tableData.length === 0) {
+ if (!getDataUrl || tableData.length === 0 || !renderLargeCharts) {
return [];
}
@@ -282,7 +304,7 @@ export const ChartPanel: React.FC<{
);
return chartData;
// Re-run when the data table changes
- }, [tableData]);
+ }, [tableData, renderLargeCharts]);
const formValues = form.watch();
@@ -307,10 +329,33 @@ export const ChartPanel: React.FC<{
if (error) {
return <ChartErrorState error={error} />;
}
+ if (!renderLargeCharts) {
+ return (
+ <Alert
+ variant="warning"
+ className="flex flex-row gap-2 items-center w-2/3 mx-auto"
+ >
+ <AlertTriangle className="h-4 w-4 mt-1" />
+ <AlertDescription className="flex flex-row justify-between items-center w-full">
+ <span>
+ Rendering large datasets is not well supported and may crash the
+ browser
+ </span>
+ <Button
+ variant="warn"
+ onClick={() => setRenderLargeCharts(true)}
+ className="h-8"
+ >
+ Proceed
+ </Button>
+ </AlertDescription>
+ </Alert>
+ );
+ }
return (
<LazyChart baseSpec={specWithoutData} data={data} height={CHART_HEIGHT} />
);
- }, [isPending, error, specWithoutData, data]);
+ }, [isPending, error, renderLargeCharts, specWithoutData, data]);
const developmentMode = import.meta.env.DEV;
diff --git a/frontend/src/components/ui/alert.tsx b/frontend/src/components/ui/alert.tsx
index f5b12b0315..7c5cc3b338 100644
--- a/frontend/src/components/ui/alert.tsx
+++ b/frontend/src/components/ui/alert.tsx
@@ -14,6 +14,8 @@ const alertVariants = cva(
destructive:
"text-destructive border-destructive/50 dark:border-destructive [&>svg]:text-destructive text-destructive",
info: "bg-(--sky-2) border-(--sky-7) text-(--sky-11)",
+ warning:
+ "bg-(--yellow-2) border-(--yellow-7) text-(--yellow-11) [&>svg]:text-(--yellow-11)",
},
},
defaultVariants: {
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index 8a2182ceb0..3216c521bb 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -690,6 +690,8 @@ export const LoadingDataTableComponent = memo(
<TablePanel
displayHeader={displayHeader}
data={data?.rows || []}
+ columns={props.totalColumns}
+ totalRows={props.totalRows}
dataTable={dataTable}
getDataUrl={props.get_data_url}
fieldTypes={props.fieldTypes}