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'} )
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())
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")
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)
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")
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())
def test_invalid_group_type(self): self.assertRaises(TypeError, Format().group, 7)
def test_valid_group_string(self): Format().group(",")
def test_valid_group_named(self): Format().group(f.Group.no)
def test_valid_groups(self): Format().groups([3])
def test_invalid_groups_empty(self): self.assertRaises(ValueError, Format().groups, [])
def test_valid_padding_string(self): Format().padding("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", }
def test_invalid_align_string(self): self.assertRaises(TypeError, Format().align, "i")
def test_invalid_align_type(self): self.assertRaises(TypeError, Format().align, 7)
def test_valid_align_named(self): Format().align(f.Align.center)
def test_valid_align_string(self): Format().align("=")
def test_invalid_groups_single_negative(self): self.assertRaises(ValueError, Format().groups, -7)
def test_invalid_groups_nested_negative(self): self.assertRaises(ValueError, Format().groups, [3, 3, -7])
def test_invalid_groups_nested_type(self): self.assertRaises(TypeError, Format().groups, [7.7, 7])
def test_invalid_group_string(self): self.assertRaises(TypeError, Format().group, "invalid")
def test_invalid_group_delimiter(self): self.assertRaises(TypeError, Format().group_delimiter, 7)
def test_valid_padding_bool(self): Format().padding(False)
def test_invalid_fill_length(self): self.assertRaises(ValueError, Format().fill, "invalid")
def test_valid_groups_multi(self): Format().groups([2, 2, 3])
def test_invalid_fill_type(self): self.assertRaises(TypeError, Format().fill, 7)
def test_valid_groups_single(self): Format().groups(3)
def test_valid_group_bool(self): Format().group(True)
def test_valid_fill(self): Format().fill(".")
def test_invalid_groups_single_type(self): self.assertRaises(TypeError, Format().groups, 7.7)