This repository has been archived by the owner on Nov 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ex_datatable.py
93 lines (70 loc) · 2.97 KB
/
ex_datatable.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Example DataTable.
TODO: See todo list at bottom!!
"""
import dash_bootstrap_components as dbc
import plotly.express as px
from dash import dcc, html
from implements import implements
from dash_charts.modules_datatable import ModuleFilteredTable
from dash_charts.utils_app import AppBase, AppInterface
from dash_charts.utils_helpers import parse_dash_cli_args
# FIXME: AttributeError: 'DataTableDemo' object has no attribute 'ids'
@implements(AppInterface) # noqa: H601
class DataTableDemo(AppBase):
"""Example creating a DataTable."""
name = 'Example DataTable'
"""Application name"""
external_stylesheets = [dbc.themes.FLATLY] # DARKLY, FLATLY, etc. (https://bootswatch.com/)
"""List of external stylesheets. Default is minimal Dash CSS. Only applies if app argument not provided."""
data_raw = None
"""All in-memory data referenced by callbacks and plotted. If modified, will impact all viewers."""
mod_table = None
"""Main table (DataTable)."""
def initialization(self) -> None:
"""Initialize ids with `self.register_uniq_ids([...])` and other one-time actions."""
super().initialization()
# Load sample plotly express data to populate the datatable
self.data_raw = px.data.gapminder()
# Register modules
self.mod_table = ModuleFilteredTable('filtered_table')
self.modules = [
self.mod_table,
]
def create_elements(self) -> None:
"""Initialize charts and tables."""
...
def return_layout(self) -> dict:
"""Return Dash application layout.
Returns:
dict: Dash HTML object
"""
return dbc.Container([
dbc.Col([
dcc.Markdown(self.mod_table.table.filter_summary),
html.Br(),
html.H1(self.name),
self.mod_table.return_layout(self._il, self.data_raw),
]),
])
def create_callbacks(self) -> None:
"""Create Dash callbacks."""
... # No callbacks necessary for this simple example
instance = DataTableDemo
app = instance()
app.create()
if __name__ == '__main__':
app.run(**parse_dash_cli_args())
else:
FLASK_HANDLE = app.get_server()
# TODO: CLICKABLE POPUPS
# - Datatable
# - Have click able icon in first column of table that triggers a dbc modal with additional information
# - Would have layout determined in callback. Could be used to show a timeline, full traceback, or other long
# form data that can't be displayed in condensed table format
# - dbc modal: https://dash-bootstrap-components.opensource.faculty.ai/l/components/modal
# - Would require pattern matching callback: https://dash.plotly.com/pattern-matching-callbacks
# # TODO: See: https://dash.plot.ly/datatable/interactivity
# > ('datatable-id...', 'derived_virtual_row_ids'),
# > ('datatable-id...', 'selected_row_ids'),
# > ('datatable-id...', 'active_cell'),
# TODO: Formatting (Typing): https://dash.plot.ly/datatable/typing