+st_df_table
+ +Streamlit dataframe display
+ +alternative to st.table
with configuration displaying Pandas DataFrame
+ + + + + +
+ +Installation instructions
+ +pip install st-df-table
+
+Usage instructions
+ +import pandas as pd
+from st_df_table import st_table
+
+data = {
+ "Column A": [1, 2, 3, 4, 5, 6],
+ "Column C": [True, False, True, False, True, False],
+ "Column B": ["A", "B", "C", "F", "G", "H"],
+}
+
+df = pd.DataFrame(data)
+st_table(df)
+
+st_table(
+ df,
+ head_align="left",
+ data_align="left",
+ head_bg_color="red",
+ head_color="blue",
+ head_font_weight="normal",
+ border_color="red",
+ border_width="3",
+)
+
+st_table(
+ df,
+ head_align="right",
+ data_align="right",
+ data_bg_color="green",
+ data_color="yellow",
+ data_font_weight="bold",
+ bordered=False,
+ sortable=False,
+)
+
+import string
+import numpy as np
+import pandas as pd
+from st_df_table import st_table
+
+df = pd.DataFrame(
+ {
+ "Column A": list(range(1, 101)),
+ "Column B": np.random.choice(list(string.ascii_uppercase), size=100),
+ "Column C": np.random.rand(100),
+ }
+)
+
+st_table(
+ df,
+ border_width=4,
+ border_color="red",
+ paginated=True,
+ pagination_size_per_page=7,
+ pagination_bar_size=4,
+ pagination_text_color="blue",
+ pagination_bg_color="yellow",
+ pagination_border_color="green",
+ pagination_active_color="yellow",
+)
+
+Changelog
+ +All notable changes to this project will be documented in this file.
+ +The format is based on Keep a Changelog, +and this project adheres to Semantic Versioning.
+ +[0.0.5] - 2024-10-26
+ +Added
+ +-
+
- configurable pagination +
[0.0.4] - 2024-10-25
+ +Added
+ +-
+
- font and font size +
[0.0.3] - 2024-10-25
+ +Changed
+ +-
+
- removed dependency to bootstrap.min.css +
[0.0.2] - 2024-10-25
+ +Fixed
+ +-
+
- build +
[0.0.1] - 2024-10-25 - deleted
+ +Added
+ +-
+
- initial version +
1""" + 2 .. include:: ../README.md + 3 .. include:: ../CHANGELOG.md + 4""" + 5 + 6import os + 7 + 8import pandas as pd + 9import streamlit.components.v1 as components + 10 + 11_RELEASE = True + 12 + 13if os.getenv("_ST_TABLE_NOT_RELEASE_"): + 14 _RELEASE = False + 15 + 16if not _RELEASE: + 17 _component_func = components.declare_component( + 18 "st_table", + 19 url="http://localhost:3001", + 20 ) + 21else: + 22 parent_dir = os.path.dirname(os.path.abspath(__file__)) + 23 build_dir = os.path.join(parent_dir, "frontend/build") + 24 _component_func = components.declare_component("st_table", path=build_dir) + 25 + 26 + 27def st_table( + 28 df: pd.DataFrame, + 29 head_align: str = "center", + 30 data_align: str = "left", + 31 head_bg_color: str = "white", + 32 data_bg_color: str = "white", + 33 head_color: str = "black", + 34 data_color: str = "black", + 35 head_font_weight: str = "bold", + 36 data_font_weight: str = "normal", + 37 bordered: bool = True, + 38 border_color: str = "black", + 39 border_width: int = 1, + 40 table_width: int = None, + 41 sortable: bool = True, + 42 font: str = "Arial", + 43 font_size: int = 16, + 44 paginated: bool = False, + 45 pagination_size_per_page: int = 10, + 46 pagination_bar_size: int = 5, + 47 pagination_text_color: str = "black", + 48 pagination_bg_color: str = "white", + 49 pagination_border_color: str = "black", + 50 pagination_active_color: str = "white", + 51 pagination_active_border_color: str = "black", + 52 pagination_active_bg_color: str = "gray", + 53 pagination_hover_color: str = "white", + 54 pagination_hover_bg_color: str = "gray", + 55 key=None, + 56): + 57 """Displays Pandas DataFrame + 58 + 59 :param df: pd.DataFrame + 60 :param head_align: str - aligning table header, values are: "center", "left", "right" + 61 :param data_align: str - align table data, values are: "center", "left", "right" + 62 :param head_bg_color: str - table header background color + 63 :param data_bg_color: str - table data background color + 64 :param head_color: str - table header text color + 65 :param data_color: str - table data text color + 66 :param head_font_weight: str - table header font weight + 67 :param data_font_weight: str - table data font weight + 68 :param bordered: bool - table bordered + 69 :param border_color: str - table border color + 70 :param border_width: int - table border width in pixels + 71 :param table_width: int - table width in pixels + 72 :param sortable: bool - table columns sortable + 73 :param font: str - table font name + 74 :param font_size: int - table font size in pixels + 75 :param paginated: bool - table paginated - **if this is False all below pagination parameters are disregarded** + 76 :param pagination_size_per_page: int - number of records per page + 77 :param pagination_bar_size: int - pagination bar size + 78 :param pagination_text_color: str - text color of pagination bar + 79 :param pagination_bg_color: str - background color of pagination bar + 80 :param pagination_border_color: str - border color of pagination bar + 81 :param pagination_active_color: str - active text color of pagination bar + 82 :param pagination_active_border_color: str - active border color of pagination bar + 83 :param pagination_active_bg_color: str - active background color of pagination bar + 84 :param pagination_hover_color: str - hover text color of pagination bar + 85 :param pagination_hover_bg_color: str - hover background color of pagination bar + 86 :param key: str + 87 An optional key that uniquely identifies this component. If this is + 88 None, and the component's arguments are changed, the component will + 89 be re-mounted in the Streamlit frontend and lose its current state. + 90 + 91 :return: none + 92 + 93 """ + 94 columns = [{"dataField": col, "text": col, "sort": sortable} for col in df.columns] + 95 data = df.reset_index().to_dict(orient="records") + 96 _component_func( + 97 columns=columns, + 98 data=data, + 99 head_align=head_align, +100 data_align=data_align, +101 head_bg_color=head_bg_color, +102 data_bg_color=data_bg_color, +103 head_color=head_color, +104 data_color=data_color, +105 head_font_weight=head_font_weight, +106 data_font_weight=data_font_weight, +107 bordered=bordered, +108 border_color=border_color, +109 border_width=border_width, +110 table_width=table_width, +111 sortable=sortable, +112 font=font, +113 font_size=font_size, +114 paginated=paginated, +115 pagination_size_per_page=pagination_size_per_page, +116 pagination_bar_size=pagination_bar_size, +117 pagination_text_color=pagination_text_color, +118 pagination_bg_color=pagination_bg_color, +119 pagination_border_color=pagination_border_color, +120 pagination_active_color=pagination_active_color, +121 pagination_active_border_color=pagination_active_border_color, +122 pagination_active_bg_color=pagination_active_bg_color, +123 pagination_hover_color=pagination_hover_color, +124 pagination_hover_bg_color=pagination_hover_bg_color, +125 key=key, +126 ) +
28def st_table( + 29 df: pd.DataFrame, + 30 head_align: str = "center", + 31 data_align: str = "left", + 32 head_bg_color: str = "white", + 33 data_bg_color: str = "white", + 34 head_color: str = "black", + 35 data_color: str = "black", + 36 head_font_weight: str = "bold", + 37 data_font_weight: str = "normal", + 38 bordered: bool = True, + 39 border_color: str = "black", + 40 border_width: int = 1, + 41 table_width: int = None, + 42 sortable: bool = True, + 43 font: str = "Arial", + 44 font_size: int = 16, + 45 paginated: bool = False, + 46 pagination_size_per_page: int = 10, + 47 pagination_bar_size: int = 5, + 48 pagination_text_color: str = "black", + 49 pagination_bg_color: str = "white", + 50 pagination_border_color: str = "black", + 51 pagination_active_color: str = "white", + 52 pagination_active_border_color: str = "black", + 53 pagination_active_bg_color: str = "gray", + 54 pagination_hover_color: str = "white", + 55 pagination_hover_bg_color: str = "gray", + 56 key=None, + 57): + 58 """Displays Pandas DataFrame + 59 + 60 :param df: pd.DataFrame + 61 :param head_align: str - aligning table header, values are: "center", "left", "right" + 62 :param data_align: str - align table data, values are: "center", "left", "right" + 63 :param head_bg_color: str - table header background color + 64 :param data_bg_color: str - table data background color + 65 :param head_color: str - table header text color + 66 :param data_color: str - table data text color + 67 :param head_font_weight: str - table header font weight + 68 :param data_font_weight: str - table data font weight + 69 :param bordered: bool - table bordered + 70 :param border_color: str - table border color + 71 :param border_width: int - table border width in pixels + 72 :param table_width: int - table width in pixels + 73 :param sortable: bool - table columns sortable + 74 :param font: str - table font name + 75 :param font_size: int - table font size in pixels + 76 :param paginated: bool - table paginated - **if this is False all below pagination parameters are disregarded** + 77 :param pagination_size_per_page: int - number of records per page + 78 :param pagination_bar_size: int - pagination bar size + 79 :param pagination_text_color: str - text color of pagination bar + 80 :param pagination_bg_color: str - background color of pagination bar + 81 :param pagination_border_color: str - border color of pagination bar + 82 :param pagination_active_color: str - active text color of pagination bar + 83 :param pagination_active_border_color: str - active border color of pagination bar + 84 :param pagination_active_bg_color: str - active background color of pagination bar + 85 :param pagination_hover_color: str - hover text color of pagination bar + 86 :param pagination_hover_bg_color: str - hover background color of pagination bar + 87 :param key: str + 88 An optional key that uniquely identifies this component. If this is + 89 None, and the component's arguments are changed, the component will + 90 be re-mounted in the Streamlit frontend and lose its current state. + 91 + 92 :return: none + 93 + 94 """ + 95 columns = [{"dataField": col, "text": col, "sort": sortable} for col in df.columns] + 96 data = df.reset_index().to_dict(orient="records") + 97 _component_func( + 98 columns=columns, + 99 data=data, +100 head_align=head_align, +101 data_align=data_align, +102 head_bg_color=head_bg_color, +103 data_bg_color=data_bg_color, +104 head_color=head_color, +105 data_color=data_color, +106 head_font_weight=head_font_weight, +107 data_font_weight=data_font_weight, +108 bordered=bordered, +109 border_color=border_color, +110 border_width=border_width, +111 table_width=table_width, +112 sortable=sortable, +113 font=font, +114 font_size=font_size, +115 paginated=paginated, +116 pagination_size_per_page=pagination_size_per_page, +117 pagination_bar_size=pagination_bar_size, +118 pagination_text_color=pagination_text_color, +119 pagination_bg_color=pagination_bg_color, +120 pagination_border_color=pagination_border_color, +121 pagination_active_color=pagination_active_color, +122 pagination_active_border_color=pagination_active_border_color, +123 pagination_active_bg_color=pagination_active_bg_color, +124 pagination_hover_color=pagination_hover_color, +125 pagination_hover_bg_color=pagination_hover_bg_color, +126 key=key, +127 ) +
Displays Pandas DataFrame
+ +Parameters
+ +-
+
- df: pd.DataFrame +
- head_align: str - aligning table header, values are: "center", "left", "right" +
- data_align: str - align table data, values are: "center", "left", "right" +
- head_bg_color: str - table header background color +
- data_bg_color: str - table data background color +
- head_color: str - table header text color +
- data_color: str - table data text color +
- head_font_weight: str - table header font weight +
- data_font_weight: str - table data font weight +
- bordered: bool - table bordered +
- border_color: str - table border color +
- border_width: int - table border width in pixels +
- table_width: int - table width in pixels +
- sortable: bool - table columns sortable +
- font: str - table font name +
- font_size: int - table font size in pixels +
- paginated: bool - table paginated - if this is False all below pagination parameters are disregarded +
- pagination_size_per_page: int - number of records per page +
- pagination_bar_size: int - pagination bar size +
- pagination_text_color: str - text color of pagination bar +
- pagination_bg_color: str - background color of pagination bar +
- pagination_border_color: str - border color of pagination bar +
- pagination_active_color: str - active text color of pagination bar +
- pagination_active_border_color: str - active border color of pagination bar +
- pagination_active_bg_color: str - active background color of pagination bar +
- pagination_hover_color: str - hover text color of pagination bar +
- pagination_hover_bg_color: str - hover background color of pagination bar +
- key: str +An optional key that uniquely identifies this component. If this is +None, and the component's arguments are changed, the component will +be re-mounted in the Streamlit frontend and lose its current state. +
Returns
+ +++none
+