Any help here would be greatly appreciated! I have the early stages of a Dash app that’s based on this structure from the Dash sample apps. Basically, I have an app.py
script that manages the app layout and the callbacks with a bit of it shown below:
app = dash.Dash(__name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}],
suppress_callback_exceptions=True)
server = app.server
UPLOAD_FOLDER_ROOT = <folder_path>
du.configure_upload(app, UPLOAD_FOLDER_ROOT, use_upload_id=True)
def live_layout():
return html.Div([dcc.Location(id="url", refresh=False), html.Div(id="page-content")])
@app.callback(Output('upload-status', 'children'),
Input('data-uploader', 'isCompleted'),
State('data-uploader', 'fileNames'), )
def upload_status(iscompleted, filename):
...
@app.callback([Output('load-dataset', 'children'),
Output('data-cols', 'options')],
[Input('data-uploader', 'isCompleted'),
Input('data-uploader', 'fileNames')],
State('data-uploader', 'upload_id'))
def load_data(iscompleted, filename, upload_id):
...
@app.callback(Output("page-content", "children"), [Input("url", "pathname")])
def display_page(pathname):
if pathname == "/data-cleaning/debugging":
return debugging.create_layout(app)
elif pathname == "/data-cleaning/errors-report":
return errorsReport.create_layout(app)
elif pathname == "/data-cleaning/solutions-report":
return solutionsReport.create_layout(app)
elif pathname == "/data-cleaning/cleaned-data":
return cleanedData.create_layout(app)
elif pathname == "/data-cleaning/supporting-documentation":
return supportingDocumentation.create_layout(app)
else:
return overview.create_layout(app)
app.layout = live_layout
if __name__ == "__main__":
app.run_server(debug=True)
I have not included all the callbacks or the functions of them for brevity, but essentially, a user is allowed to upload a dataset using the dash_uploader
function (more detail here) and then they click a button where scripts are used to clean the data for errors.
Each page (tab) usually starts with the following after importing the relevant libraries, where Header is a function to create a standardized page header:
def create_layout(app):
# Page layouts
return html.Div(
[
html.Div([Header(app)]),
# page 1
html.Div(
[
That’s the short of it, but basically, when transitioning from one tab to another, the data is cleared from memory and the user will have to start all over again. I have read many topics of dcc.Store
and persistence
but I really do not know how to go about implementing it based on the structure that I have. I would really appreciate any guidance as I am new to Dash.
Ideally, after the user uploads the dataset, I would like it to be in local memory and then be used by all the other callbacks, and not refresh the tabs every time a user navigates to another.