Пример #1
0
def make_datatable(df, dataset):
    global table_index
    table_index += 1

    return dash_table.DataTable(
        id={'type': 'datatable_table', 'dataset': dataset, 'index': table_index},
        columns=[
            (dict(name=i, id=i, hideable=False, type='numeric',
                  format=Format(precision=4, scheme=Scheme.fixed, trim=Trim.yes))
             if i != 'Species' else
             dict(name=i, id=i))
            # {"name": i, "id": i, "hideable": True}
            for i in df.columns
            if i not in ['numIndex', 'id']

        ],
        data=df.to_dict('records'),  # the contents of the table
        filter_action="native",  # allow filtering of data by user ('native') or not ('none')
        sort_action="native",  # enables data to be sorted per-column by user or not ('none')
        sort_mode="single",  # sort across 'multi' or 'single' columns
        # column_selectable="multi",  # allow users to select 'multi' or 'single' columns
        row_selectable="multi",  # allow users to select 'multi' or 'single' rows
        # row_deletable=True,  # choose if user can delete a row (True) or not (False)
        page_size=8,  # number of rows visible per page
        style_cell={  # ensure adequate header width when text is shorter than cell's text
            #        'minWidth': 95, 'maxWidth': 95, 'width': 95,
            'fontSize': 12, 'font-family': 'sans-serif'

        },
        style_data={  # overflow cells' content into multiple lines
            'whiteSpace': 'normal',
            'height': 'auto'}

    )
Пример #2
0
    def test_complex_and_valid_in_fluent(self):
        res = (Format().align(f.Align.center).fill(".").group(
            f.Group.yes).padding(True).padding_width(10).precision(6).scheme(
                "s").sign(f.Sign.parantheses).symbol(
                    f.Symbol.yes).symbol_prefix("a").symbol_suffix("bc").
               decimal_delimiter("x").group_delimiter("y").groups(
                   [2, 2, 2, 3]).nully("N/A").si_prefix(f.Prefix.none))

        self.validate_complex(res.to_plotly_json())
Пример #3
0
 def make_table(df: pd.DataFrame) -> Tuple[List[Any], List[Any]]:
     df.columns = df.columns.map("|".join)
     columns = [{
         "id": col,
         "name": [col.split("|")[0], col.split("|")[1]],
         "type": "numeric",
         "format": Format(precision=3),
     } for col in df.columns]
     return columns, df.iloc[::-1].to_dict("records")
Пример #4
0
 def set_column_format(self, col: str) -> Union[dict, Format]:
     if "%" in col:
         return {"specifier": ".1f"}
     if self._use_si_format:
         return {
             "locale": {
                 "symbol": ["", ""]
             },
             "specifier": f"$.{self._precision}s",
         }
     return Format(precision=self._precision)
Пример #5
0
 def make_table(df: pd.DataFrame) -> Tuple[List[Any], List[Any]]:
     """Return format needed for dash table"""
     col_order = ["PARAMETER", "Avg", "Stddev", "P90", "P10", "Min", "Max"]
     df = df.reindex(col_order, axis=1, level=0)
     df.columns = df.columns.map("|".join)
     columns = [{
         "id": col,
         "name": [col.split("|")[0], col.split("|")[1]],
         "type": "numeric",
         "format": Format(precision=3),
     } for col in df.columns]
     return columns, df.to_dict("records")
Пример #6
0
    def test_complex_and_valid_in_ctor(self):
        res = Format(
            align=f.Align.center,
            fill=".",
            group=f.Group.yes,
            padding=True,
            padding_width=10,
            precision=6,
            scheme="s",
            sign=f.Sign.parantheses,
            symbol=f.Symbol.yes,
            symbol_prefix="a",
            symbol_suffix="bc",
            decimal_delimiter="x",
            group_delimiter="y",
            groups=[2, 2, 2, 3],
            nully="N/A",
            si_prefix=f.Prefix.none,
        )

        self.validate_complex(res.to_plotly_json())
Пример #7
0
 def test_invalid_group_type(self):
     self.assertRaises(TypeError, Format().group, 7)
Пример #8
0
 def test_valid_group_string(self):
     Format().group(",")
Пример #9
0
 def test_valid_group_named(self):
     Format().group(f.Group.no)
Пример #10
0
 def test_valid_groups(self):
     Format().groups([3])
Пример #11
0
 def test_invalid_groups_empty(self):
     self.assertRaises(ValueError, Format().groups, [])
Пример #12
0
 def test_valid_padding_string(self):
     Format().padding("0")
Пример #13
0
             labelStyle={"display": "inline-block"},
             style={"display": "inline-block"},
             value="locked_y_axis",
         ),
     ]
 ),
 html.Div(id="percent-chart"),
 dash_table.DataTable(
     id="table",
     columns=[
         {"name": "Servant", "id": "Servant"},
         {
             "name": "Count",
             "id": "Count",
             "type": "numeric",
             "format": Format(group=","),
         },
         {
             "name": "% have",
             "id": "% have",
             "type": "numeric",
             "format": FormatTemplate.percentage(2),
         },
     ],
     style_cell={"fontSize": "16px"},
     style_cell_conditional=[
         {
             "if": {"column_id": "Servant"},
             "textAlign": "left",
             "fontFamily": "sans-serif",
         }
Пример #14
0
 def test_invalid_align_string(self):
     self.assertRaises(TypeError, Format().align, "i")
Пример #15
0
 def test_invalid_align_type(self):
     self.assertRaises(TypeError, Format().align, 7)
Пример #16
0
 def test_valid_align_named(self):
     Format().align(f.Align.center)
Пример #17
0
 def test_valid_align_string(self):
     Format().align("=")
Пример #18
0
 def test_invalid_groups_single_negative(self):
     self.assertRaises(ValueError, Format().groups, -7)
Пример #19
0
 def test_invalid_groups_nested_negative(self):
     self.assertRaises(ValueError, Format().groups, [3, 3, -7])
Пример #20
0
 def test_invalid_groups_nested_type(self):
     self.assertRaises(TypeError, Format().groups, [7.7, 7])
Пример #21
0
 def test_invalid_group_string(self):
     self.assertRaises(TypeError, Format().group, "invalid")
Пример #22
0
 def test_invalid_group_delimiter(self):
     self.assertRaises(TypeError, Format().group_delimiter, 7)
Пример #23
0
 def test_valid_padding_bool(self):
     Format().padding(False)
Пример #24
0
 def test_invalid_fill_length(self):
     self.assertRaises(ValueError, Format().fill, "invalid")
Пример #25
0
 def test_valid_groups_multi(self):
     Format().groups([2, 2, 3])
Пример #26
0
 def test_invalid_fill_type(self):
     self.assertRaises(TypeError, Format().fill, 7)
Пример #27
0
 def test_valid_groups_single(self):
     Format().groups(3)
Пример #28
0
 def test_valid_group_bool(self):
     Format().group(True)
Пример #29
0
 def test_valid_fill(self):
     Format().fill(".")
Пример #30
0
 def test_invalid_groups_single_type(self):
     self.assertRaises(TypeError, Format().groups, 7.7)