Skip to content

Commit f076cf0

Browse files
committed
✨ Feat(streamlit_reportview.py): Display dataframes in streamlit apps with st-aggrid to add searching and filtering features. Fixes #62
1 parent bb1220f commit f076cf0

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ version = "0.1.0"
1313
[tool.poetry.dependencies]
1414
python = ">=3.9,<3.9.7 || >3.9.7,<4.0"
1515
streamlit = "1.39.0"
16+
streamlit-aggrid = "1.1.0"
17+
quarto-cli = "*"
1618
plotly = "5.15.0"
1719
pyvis = "^0.3.2"
1820
pandas = {extras = ["parquet"], version = "^2.2.3"}
@@ -28,6 +30,7 @@ vl-convert-python = "^1.7.0"
2830
dataframe-image = "^0.2.6"
2931
strenum = { version = "^0.4.15", python = "<3.11" }
3032
pyyaml = "^6.0.2"
33+
3134
# optional doc depencencies, follow approach as described here:
3235
# https://github.com/python-poetry/poetry/issues/2567#issuecomment-646766059
3336
sphinx = {version="*", optional=true}
@@ -36,15 +39,12 @@ myst-nb = {version="*", optional=true}
3639
ipywidgets = {version="*", optional=true}
3740
sphinx-new-tab-link = {version = "!=0.2.2", optional=true}
3841
jupytext = {version="*", optional=true}
39-
# quarto
40-
quarto-cli = "*"
4142

4243
[tool.poetry.group.dev.dependencies]
4344
ipykernel = {version="^6.29.5", optional=true}
4445

4546
[tool.poetry.requires-plugins]
4647
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
47-
4848

4949
[tool.poetry-dynamic-versioning]
5050
enable = true

src/vuegen/streamlit_reportview.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,26 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
466466
read_function = read_function_mapping[file_extension]
467467
dataframe_content.append(f"""df = pd.{read_function.__name__}('{dataframe.file_path}')""")
468468

469-
# Display the dataframe
470-
dataframe_content.append("st.dataframe(df, use_container_width=True)")
471-
469+
# Displays a DataFrame using AgGrid with configurable options.
470+
dataframe_content.append("""
471+
# Displays a DataFrame using AgGrid with configurable options.
472+
grid_builder = GridOptionsBuilder.from_dataframe(df)
473+
grid_builder.configure_default_column(editable=True, groupable=True)
474+
grid_builder.configure_side_bar(filters_panel=True, columns_panel=True)
475+
grid_builder.configure_selection(selection_mode="multiple")
476+
grid_builder.configure_pagination(enabled=True, paginationAutoPageSize=False, paginationPageSize=20)
477+
grid_options = grid_builder.build()
478+
479+
AgGrid(df, gridOptions=grid_options)
480+
481+
# Button to download the df
482+
df_csv = utils.convert_df(df)
483+
st.download_button(
484+
label=f"Download dataframe as CSV",
485+
data=df,
486+
file_name=f"dataframe.csv",
487+
mime='text/csv',
488+
)""")
472489
except Exception as e:
473490
self.report.logger.error(f"Error generating content for DataFrame: {dataframe.title}. Error: {str(e)}")
474491
raise

0 commit comments

Comments
 (0)