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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: show mo.ui.table() first results from initial data (#2204)
Myles Scolnick14817a81179a
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsxindex b2b31262c8..3c69893607 100644--- a/frontend/src/plugins/impl/DataTablePlugin.tsx+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx@@ -241,7 +241,7 @@ export const LoadingDataTableComponent = memo(// Data loadingconst { data, loading, error } = useAsyncData<{rows: T[];- totalRows: number;+ totalRows: number | "too_many";}>(async () => {// If there is no data, return an empty arrayif (props.totalRows === 0) {@@ -250,38 +250,49 @@ export const LoadingDataTableComponent = memo(// Table data is a url string or an array of objectslet tableData = props.data;+ let totalRows = props.totalRows;++ // First page and no search query+ const shouldSkipSearch =+ searchQuery === "" &&+ paginationState.pageIndex === 0 &&+ filters.length === 0 &&+ sorting.length === 0;if (sorting.length > 1) {Logger.warn("Multiple sort columns are not supported");}- // If we have sort configuration, fetch the sorted data- const searchResults = await search<T>({- sort:- sorting.length > 0- ? {- by: sorting[0].id,- descending: sorting[0].desc,- }- : undefined,- query: searchQuery,- page_number: paginationState.pageIndex,- page_size: paginationState.pageSize,- filters: filters.flatMap((filter) => {- return filterToFilterCondition(- filter.id,- filter.value as ColumnFilterValue,- );- }),- });+ // If we have sort/search/filter, use the search function+ if (!shouldSkipSearch) {+ const searchResults = await search<T>({+ sort:+ sorting.length > 0+ ? {+ by: sorting[0].id,+ descending: sorting[0].desc,+ }+ : undefined,+ query: searchQuery,+ page_number: paginationState.pageIndex,+ page_size: paginationState.pageSize,+ filters: filters.flatMap((filter) => {+ return filterToFilterCondition(+ filter.id,+ filter.value as ColumnFilterValue,+ );+ }),+ });- tableData = searchResults.data;+ tableData = searchResults.data;+ totalRows = searchResults.total_rows;+ }// If we already have the data, return itif (Array.isArray(tableData)) {return {rows: tableData,- totalRows: searchResults.total_rows,+ totalRows: totalRows,};}@@ -299,7 +310,7 @@ export const LoadingDataTableComponent = memo(return {rows: tableData,- totalRows: searchResults.total_rows,+ totalRows: totalRows,};}, [sorting,@@ -337,7 +348,13 @@ export const LoadingDataTableComponent = memo(if (loading && !data) {return (<DelayMount milliseconds={200}>- <LoadingTable pageSize={props.pageSize} />+ <LoadingTable+ pageSize={+ props.totalRows !== "too_many" && props.totalRows > 0+ ? props.totalRows+ : props.pageSize+ }+ /></DelayMount>);}diff --git a/marimo/_smoke_tests/initial_table.py b/marimo/_smoke_tests/initial_table.pynew file mode 100644index 0000000000..a831c7f1a9--- /dev/null+++ b/marimo/_smoke_tests/initial_table.py@@ -0,0 +1,45 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "pandas",+# "marimo",+# ]+# ///++import marimo++__generated_with = "0.8.8"+app = marimo.App(width="medium")+++def __():+ import marimo as mo+ return mo,+++def __():+ import pandas as pd++ sample_df = pd.DataFrame(+ {+ "Name": ["Alice", "Bob", "Charlie"],+ "Age": [25, 30, 35],+ "City": ["New York", "Los Angeles", "Chicago"],+ }+ )+ return pd, sample_df+++def __(mo, sample_df):+ import time++ mo.output.replace(sample_df)+ time.sleep(5)+ return time,+++if __name__ == "__main__":+ app.run()diff --git a/pyproject.toml b/pyproject.tomlindex 40b4bf3dc9..f884d94d34 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -90,7 +90,7 @@ dev = ["pandas>=1.5.3","pandas-stubs>=1.5.3.230321","pyarrow>=15.0.2,<18",- "pyarrow-stubs>=10.0.1.9",+ "pyarrow-stubs>=2024.9.3",# For tracing debugging"opentelemetry-api~=1.26.0","opentelemetry-sdk~=1.26.0",@@ -136,7 +136,7 @@ testoptional = ["geopandas~=0.13.0","matplotlib~=3.9.2; python_version > \"3.8\"","pyarrow>=15.0.2,<18",- "pyarrow-stubs>=20240830",+ "pyarrow-stubs>=2024.9.3","pyarrow-hotfix","pillow~=10.4.0","types-Pillow~=10.2.0.20240520",