Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions backend/chainlit/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TypedDict,
TypeVar,
Union,
cast,
)

import filetype
Expand Down Expand Up @@ -179,6 +180,16 @@ def from_dict(cls, e_dict: ElementDict):
elif type == "plotly":
return Plotly(size=e_dict.get("size", "medium"), **common_params) # type: ignore[arg-type]

elif type == "dataframe":
dataframe_dict = cast(DataframeDict, e_dict)
return Dataframe(
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
show_column_visibility=dataframe_dict.get(
"showColumnVisibility", False
),
show_column_filters=dataframe_dict.get("showColumnFilters", False),
**common_params, # type: ignore[arg-type]
)

elif type == "custom":
return CustomElement(props=e_dict.get("props", {}), **common_params) # type: ignore[arg-type]
else:
Expand Down Expand Up @@ -418,24 +429,40 @@ def __post_init__(self) -> None:
super().__post_init__()


class DataframeDict(ElementDict, total=False):
showColumnVisibility: bool
showColumnFilters: bool


@dataclass
class Dataframe(Element):
"""Useful to send a pandas DataFrame to the UI."""

type: ClassVar[ElementType] = "dataframe"
size: ElementSize = "large"
data: Any = None # The type is Any because it is checked in __post_init__.
show_column_visibility: bool = False
"""Show column visibility toggle dropdown. Defaults to False in the UI."""
show_column_filters: bool = False
"""Show per-column filter inputs. Defaults to False in the UI."""

def __post_init__(self) -> None:
"""Ensures the data is a pandas DataFrame and converts it to JSON."""
from pandas import DataFrame
if self.data is not None:
from pandas import DataFrame

if not isinstance(self.data, DataFrame):
raise TypeError("data must be a pandas.DataFrame")
if not isinstance(self.data, DataFrame):
raise TypeError("data must be a pandas.DataFrame")

self.content = self.data.to_json(orient="split", date_format="iso")
self.content = self.data.to_json(orient="split", date_format="iso")
super().__post_init__()

def to_dict(self) -> DataframeDict:
d = DataframeDict(**super().to_dict())
d["showColumnVisibility"] = self.show_column_visibility
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
d["showColumnFilters"] = self.show_column_filters
return d


@dataclass
class CustomElement(Element):
Expand Down
12 changes: 12 additions & 0 deletions backend/chainlit/translations/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "একটি তারিখ বেছে নিন",
"range": "তারিখের পরিসীমা বেছে নিন"
}
},
"DataframeElement": {
"selectAll": "সব নির্বাচন করুন",
"deselectAll": "সব বাতিল করুন",
"rowsCount": "{{total}} এর মধ্যে {{filtered}} সারি",
"rowsPerPage": "{{count}} সারি",
"filterPlaceholder": "ফিল্টার...",
"columns": "কলাম",
"pageSizePlaceholder": "পেজ আকার",
"exportExcel": "Excel রপ্তানি করুন",
"clearFilters": "ফিল্টার মুছুন",
"noResults": "কোনো ফলাফল নেই।"
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@
"components": {
"MultiSelectInput": {
"placeholder": "Wähle aus..."
},
"DataframeElement": {
"selectAll": "Alle auswählen",
"deselectAll": "Alle abwählen",
"rowsCount": "{{filtered}} von {{total}} Zeilen",
"rowsPerPage": "{{count}} Zeilen",
"filterPlaceholder": "Filtern...",
"columns": "Spalten",
"pageSizePlaceholder": "Seitengröße",
"exportExcel": "Excel exportieren",
"clearFilters": "Filter löschen",
"noResults": "Keine Ergebnisse."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/el-GR.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "Επιλέξτε ημερομηνία",
"range": "Επιλέξτε εύρος ημερομηνιών"
}
},
"DataframeElement": {
"selectAll": "Επιλογή όλων",
"deselectAll": "Αποεπιλογή όλων",
"rowsCount": "{{filtered}} από {{total}} γραμμές",
"rowsPerPage": "{{count}} γραμμές",
"filterPlaceholder": "Φίλτραρισμα...",
"columns": "Στήλες",
"pageSizePlaceholder": "Μέγεθος σελίδας",
"exportExcel": "Εξαγωγή Excel",
"clearFilters": "Καθαρισμός φίλτρων",
"noResults": "Δεν βρέθηκαν αποτελέσματα."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "Pick a date",
"range": "Pick a date range"
}
},
"DataframeElement": {
"selectAll": "Select all",
"deselectAll": "Deselect all",
"rowsCount": "{{filtered}} of {{total}} rows",
"rowsPerPage": "{{count}} rows",
"filterPlaceholder": "Filter...",
"columns": "Columns",
"pageSizePlaceholder": "Page size",
"exportExcel": "Export Excel",
"clearFilters": "Clear Filters",
"noResults": "No results."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "Elige una fecha",
"range": "Elige un rango de fechas"
}
},
"DataframeElement": {
"selectAll": "Seleccionar todo",
"deselectAll": "Deseleccionar todo",
"rowsCount": "{{filtered}} de {{total}} filas",
"rowsPerPage": "{{count}} filas",
"filterPlaceholder": "Filtrar...",
"columns": "Columnas",
"pageSizePlaceholder": "Tamaño de página",
"exportExcel": "Exportar Excel",
"clearFilters": "Limpiar filtros",
"noResults": "Sin resultados."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "Choisir une date",
"range": "Choisir une plage de dates"
}
},
"DataframeElement": {
"selectAll": "Tout sélectionner",
"deselectAll": "Tout désélectionner",
"rowsCount": "{{filtered}} sur {{total}} lignes",
"rowsPerPage": "{{count}} lignes",
"filterPlaceholder": "Filtrer...",
"columns": "Colonnes",
"pageSizePlaceholder": "Taille de page",
"exportExcel": "Exporter Excel",
"clearFilters": "Effacer les filtres",
"noResults": "Aucun résultat."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/gu.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "તારીખ પસંદ કરો",
"range": "તારીખની શ્રેણી પસંદ કરો"
}
},
"DataframeElement": {
"selectAll": "બધા પસંદ કરો",
"deselectAll": "બધા રદ કરો",
"rowsCount": "{{total}} માંથી {{filtered}} પંક્તિઓ",
"rowsPerPage": "{{count}} પંક્તિઓ",
"filterPlaceholder": "ફિલ્ટર...",
"columns": "કોલમ્સ",
"pageSizePlaceholder": "પેજ કાર્યક્ષમતા",
"exportExcel": "Excel નિકાસ કરો",
"clearFilters": "ફિલ્ટર સાવ કરો",
"noResults": "કોઈ પરિણામ નથી."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/he-IL.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "בחר תאריך",
"range": "בחר טווח תאריכים"
}
},
"DataframeElement": {
"selectAll": "בחר הכל",
"deselectAll": "בטל בחירה",
"rowsCount": "{{filtered}} מתוך {{total}} שורות",
"rowsPerPage": "{{count}} שורות",
"filterPlaceholder": "סנן...",
"columns": "עמודות",
"pageSizePlaceholder": "גודל עמוד",
"exportExcel": "ייצוא Excel",
"clearFilters": "נקה סננים",
"noResults": "אין תוצאות."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "एक तारीख चुनें",
"range": "तारीख सीमा चुनें"
}
},
"DataframeElement": {
"selectAll": "सभी चुनें",
"deselectAll": "सभी हटाएं",
"rowsCount": "{{total}} में से {{filtered}} पंक्तियाँ",
"rowsPerPage": "{{count}} पंक्तियाँ",
"filterPlaceholder": "फ़िल्टर...",
"columns": "कॉलम",
"pageSizePlaceholder": "पेज आकार",
"exportExcel": "Excel निर्यात करें",
"clearFilters": "फ़िल्टर हटाएं",
"noResults": "कोई परिणाम नहीं।"
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@
"components": {
"MultiSelectInput": {
"placeholder": "Seleziona..."
},
"DataframeElement": {
"selectAll": "Seleziona tutto",
"deselectAll": "Deseleziona tutto",
"rowsCount": "{{filtered}} di {{total}} righe",
"rowsPerPage": "{{count}} righe",
"filterPlaceholder": "Filtra...",
"columns": "Colonne",
"pageSizePlaceholder": "Dimensione pagina",
"exportExcel": "Esporta Excel",
"clearFilters": "Cancella filtri",
"noResults": "Nessun risultato."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@
"single": "日付を選択",
"range": "日付範囲を選択"
}
},
"DataframeElement": {
"selectAll": "すべて選択",
"deselectAll": "すべて選択解除",
"rowsCount": "{{total}}中{{filtered}}件",
"rowsPerPage": "{{count}}行",
"filterPlaceholder": "フィルター...",
"columns": "列",
"pageSizePlaceholder": "ページサイズ",
"exportExcel": "Excelにエクスポート",
"clearFilters": "フィルターをクリア",
"noResults": "結果なし。"
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/kn.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "ದಿನಾಂಕವನ್ನು ಆಯ್ಕೆಮಾಡಿ",
"range": "ದಿನಾಂಕ ಶ್ರೇಣಿಯನ್ನು ಆಯ್ಕೆಮಾಡಿ"
}
},
"DataframeElement": {
"selectAll": "ಎಲ್ಲವನ್ನೂ ಆಯ್ಕೆ ಮಾಡಿ",
"deselectAll": "ಎಲ್ಲವನ್ನೂ ತೆಗೆದುಹಾಕಿ",
"rowsCount": "{{total}} ರಲ್ಲಿ {{filtered}} ಸಾಲುಗಳು",
"rowsPerPage": "{{count}} ಸಾಲುಗಳು",
"filterPlaceholder": "ಫಿಲ್ಟರ್...",
"columns": "ಕಾಲಮ್ಮುಗಳು",
"pageSizePlaceholder": "ಪುಟ ಗಾತ್ರೆ",
"exportExcel": "Excel ನಿರ್ಗಮಿಸಿ",
"clearFilters": "ಫಿಲ್ಟರ್ ತೆರವುಗೆಳಿಸಿ",
"noResults": "ಯಾವುದೇ ಫಲಿತಾಂಶವಿಲ್ಲ."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@
"components": {
"MultiSelectInput": {
"placeholder": "선택..."
},
"DataframeElement": {
"selectAll": "모두 선택",
"deselectAll": "모두 선택 해제",
"rowsCount": "{{total}}행 중 {{filtered}}행",
"rowsPerPage": "{{count}}행",
"filterPlaceholder": "필터...",
"columns": "열",
"pageSizePlaceholder": "페이지 크기",
"exportExcel": "Excel 내보내기",
"clearFilters": "필터 지우기",
"noResults": "결과 없음."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "തീയതി തിരഞ്ഞെടുക്കുക",
"range": "തീയതി ശ്രേണി തിരഞ്ഞെടുക്കുക"
}
},
"DataframeElement": {
"selectAll": "എല്ലാം തിരഞ്ഞെടുക്കുക",
"deselectAll": "എല്ലാം നീക്കുക",
"rowsCount": "{{total}} ല്മിന്‍ {{filtered}} വരികല്‍",
"rowsPerPage": "{{count}} വരികല്‍",
"filterPlaceholder": "ഫില്റ്റർ...",
"columns": "നിരകള്‍",
"pageSizePlaceholder": "പേജ് വലിപ്പ്",
"exportExcel": "Excel ക്ക് കയററ്റുമതി ചെയ്യുക",
"clearFilters": "ഫില്റ്റർ മായ്ക്കുക",
"noResults": "ഫലങ്ങള്‍ ഒന്നുമില്ല."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/mr.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "तारीख निवडा",
"range": "तारीख श्रेणी निवडा"
}
},
"DataframeElement": {
"selectAll": "सर्व निवडा",
"deselectAll": "सर्व रद्द करा",
"rowsCount": "{{total}} पैकी {{filtered}} पंक्ती",
"rowsPerPage": "{{count}} पंक्ती",
"filterPlaceholder": "फिल्टर...",
"columns": "स्तंभ",
"pageSizePlaceholder": "पृष्ठ आकार",
"exportExcel": "Excel निर्यात करा",
"clearFilters": "फिल्टर साफ करा",
"noResults": "कोणतेही परिणाम नाही."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "Kies een datum",
"range": "Kies een datumbereik"
}
},
"DataframeElement": {
"selectAll": "Alles selecteren",
"deselectAll": "Alles deselecteren",
"rowsCount": "{{filtered}} van {{total}} rijen",
"rowsPerPage": "{{count}} rijen",
"filterPlaceholder": "Filteren...",
"columns": "Kolommen",
"pageSizePlaceholder": "Paginagrootte",
"exportExcel": "Excel exporteren",
"clearFilters": "Filters wissen",
"noResults": "Geen resultaten."
}
}
}
12 changes: 12 additions & 0 deletions backend/chainlit/translations/ta.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@
"single": "தேதியைத் தேர்ந்தெடுக்கவும்",
"range": "தேதி வரம்பைத் தேர்ந்தெடுக்கவும்"
}
},
"DataframeElement": {
"selectAll": "அனைத்தையும் தேர்ந்தெடு",
"deselectAll": "அனைத்தையும் நீக்கு",
"rowsCount": "{{total}} இல் {{filtered}} வரிசைகள்",
"rowsPerPage": "{{count}} வரிசைகள்",
"filterPlaceholder": "வடிகட்டு...",
"columns": "நிரல்கள்",
"pageSizePlaceholder": "பக்க அளவு",
"exportExcel": "Excel ஏற்றுமதி",
"clearFilters": "வடிகட்டை அழி",
"noResults": "உள்ளடக்கம் இல்லை."
}
}
}
Loading
Loading