File size: 1,434 Bytes
b4451e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Statistical Summary Table plugin"""

from typing import Any
import logging
from dash import html, dash_table
from ..base import BaseTablePlugin

logger = logging.getLogger(__name__)


class SummaryStatisticsTablePlugin(BaseTablePlugin):
    """Summary statistics table (describe())."""

    name = "Summary Statistics Table"

    def controls(self) -> Any:
        """Summary table has no controls."""
        return html.Div("No controls for this table.")

    def render(self, **kwargs: Any) -> Any:
        """Render the summary statistics table."""
        desc = self.dataframe.describe(include="all").transpose().reset_index()
        desc = desc.rename(columns={"index": "Column"})

        return dash_table.DataTable(  # type: ignore
            id="summary-stats-table",
            columns=[{"name": c, "id": c} for c in desc.columns],
            data=desc.to_dict("records"),
            style_table={"overflowX": "auto"},
            style_cell={
                "textAlign": "center",
                "padding": "6px",
                "border": "1px solid #ccc",
                "fontFamily": "Times New Roman, Times, serif",
            },
            style_header={
                "backgroundColor": "#f0f0f0",
                "fontWeight": "bold",
            },
        )

    def register_callbacks(self, app: Any) -> Any:
        """Register callbacks for the summary statistics table."""
        return None