Skip to content

Commit 0d5c0d8

Browse files
committed
🚧 add streamlit support using selection dropdown menu
1 parent dbd468d commit 0d5c0d8

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/vuegen/streamlit_reportview.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
import sys
4+
import textwrap
45
from pathlib import Path
56
from typing import List
67

@@ -641,13 +642,40 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
641642
self.report.logger.error(
642643
f"Unsupported file extension: {file_extension}. Supported extensions are: {', '.join(fmt.value for fmt in r.DataFrameFormat)}."
643644
)
645+
# ? Does this skip the execution step?
646+
647+
if file_extension in [
648+
r.DataFrameFormat.XLS.value_with_dot,
649+
r.DataFrameFormat.XLSX.value_with_dot,
650+
]:
651+
dataframe_content.append("selected_sheet = 0")
652+
sheet_names = table_utils.get_sheet_names(dataframe.file_path)
653+
if len(sheet_names) > 1:
654+
# If there are multiple sheets, ask the user to select one
655+
656+
dataframe_content.append(
657+
textwrap.dedent(
658+
f"""\
659+
sheet_names = table_utils.get_sheet_names("{dataframe.file_path}")
660+
selected_sheet = st.selectbox("Select a sheet to display", options=sheet_names)
661+
"""
662+
)
663+
)
644664

645665
# Load the DataFrame using the correct function
646666
read_function = read_function_mapping[file_extension]
647-
dataframe_content.append(
648-
f"""df = pd.{read_function.__name__}('{dataframe.file_path}')\n"""
649-
)
650-
667+
if file_extension in [
668+
r.DataFrameFormat.XLS.value_with_dot,
669+
r.DataFrameFormat.XLSX.value_with_dot,
670+
]:
671+
dataframe_content.append(
672+
f"""df = pd.{read_function.__name__}('{dataframe.file_path}', sheet_name=selected_sheet)\n"""
673+
)
674+
else:
675+
dataframe_content.append(
676+
f"""df = pd.{read_function.__name__}('{dataframe.file_path}')\n"""
677+
)
678+
# ! iterate over sheets in DataFrame
651679
# Displays a DataFrame using AgGrid with configurable options.
652680
dataframe_content.append(
653681
"""
@@ -1065,6 +1093,7 @@ def _generate_component_imports(self, component: r.Component) -> List[str]:
10651093
"dataframe": [
10661094
"import pandas as pd",
10671095
"from st_aggrid import AgGrid, GridOptionsBuilder",
1096+
"from vuegen import table_utils",
10681097
],
10691098
"markdown": ["import requests"],
10701099
"chatbot": ["import time", "import json", "import requests"],

0 commit comments

Comments
 (0)