main.py
def init_app(server: Flask, path: str):
dashapp = Dash(__name__, server=server, external_stylesheets=dmc.styles.ALL,
url_base_pathname=path,
use_pages=True,
suppress_callback_exceptions=True)
store = dcc.Store(id='globstore', data=1)
layout = dmc.AppShell(
children=[
dmc.AppShellHeader(),
dmc.AppShellNavbar(
children=[
dmc.NavLink(
label="События",
leftSection=DashIconify(icon='material-symbols:e911-emergency', height=24),
href='/events/',
)
],
p='md'
),
dmc.AppShellMain([store, page_container]),
],
)
dashapp.layout = dmc.MantineProvider(layout, forceColorScheme='dark')
return dashapp.server
pages/events.py
dash.register_page(__name__)
...
table = dag.AgGrid(
id="events-table",
className='ag-theme-quartz-dark',
dashGridOptions={'pagination': True,
'paginationPageSize': 30,
'domLayout': 'autoHeight',
'rowSelection': 'multiple',
'suppressRowClickSelection': True},
getRowId='params.data._id',
rowClassRules=rowClassRules,
style={'height': None},
eventListeners={'rowDataUpdated': ['refreshCells(params, setGridProps)']}
)
...
@callback(
Output('events-table', 'rowTransaction', allow_duplicate=True),
Input('globstore', 'data'),
prevent_initial_call=True,
)
def update_table(transaction):
return {'update': [transaction]}
layout = html.Div(
children=[
dmc.Container(table, fluid=True, style={"marginTop": 7}),
]
)
Column ‘description’ is defined as follows
{
'field': 'description',
'headerName': 'Description',
'flex': 1,
'cellRenderer': 'eventLink',
'wrapText': True,
}
The links in this column have format ‘https://localhost/event/<event_id>’
pages/event.py
dash.register_page(__name__, path_template='/event/<event_id>')
...
@callback(
Output('globstore', 'data'),
Input('close-event-btn', 'n_clicks'),
State('event-id', 'data'),
State('globstore', 'data'),
prevent_initial_call=True
)
def write_transaction(clicks, event_id, data):
if not clicks:
raise PreventUpdate
transaction = {'_id': event_id, 'is_closed': True}
return transaction
My notes:
- Callback write_transaction is working. It writes transaction details in globstore
- Callback update_table doesn’t trigger. ONE TIME during many runs is was triggered. I don’t know how)) But It didn’t happen anymore. And I think that time callback write_transaction wasn’t triggered.
- I’ve found Passing data between pages via a dcc.Store · Issue #94 · plotly/dash-labs · GitHub
- I use Flask in my project so that’s the reason why my dashapp is defined inside INIT_APP function.