Creating the App¶
Module Contents¶
Dash app creation following Flask Application Factory methods
As Dash apps are, under the hood, Flask apps, it should be best practice to follow established Flask recommendations, where possible. One of these is the factory method, where necessary components are defined in submodule and linked to the app in a create_app function. This has several advantages, including modular structure and making the entry point script very clean.
-
dash_covid19.create_app(testing: bool = False) → Tuple[dash.dash.Dash, flask.app.Flask]¶ Initialise the dash app
This function is designed to be called in the wsgi entry point script to create the Dash app.
Note
The option to specify parameters exists solely for testing. When called in the entry point, defaults should be used
- Parameters
df (pd.DataFrame) – The data to be used in the app
cols (List[str]) – The columns that will be selectable
- Returns
Containing two objects:
- appdash.dash.Dash
The created Dash app
- serverflask.app.Flask
The Flask instance associated with the Dash app
- Return type
Tuple[dash.dash.Dash, flask.app.Flask]
Function: init_data¶
Module: Data
To comply with the Flask Application factory layout - as Dash apps are really just Flask apps under the hood - this function initialises the data for the app.
-
dash_covid19.data.init_data(testing: bool = False) → Tuple[pandas.core.frame.DataFrame, List[str]]¶ Initialise data and return default
This function is called with create_app() to initialise the app data in accordance with Flask Application Factory principles.
Note
The parameters exist only for the sake of specifying reduced, mock data during testing When called in the wsgi entry point, the defaults should be used
- Parameters
testing (bool) – Whether to use mock data
- Returns
Containing two objects:
- datapd.DataFrame
The data to be used within the app
- columnsList[str]
Which columns are to be selectable throughout the app
- Return type
Tuple
Function: init_layouts¶
Module: Layouts
To comply with the Flask Application factory layout - as Dash apps are really just Flask apps under the hood - this function initialises the layouts for the app.
As the app is multipage, each page layout is currently stored as a key: value pair in a dictionary, facilitating easy page changing by using a callback that matches the href to a key.
One could also write this as multiple, small dash apps, each registered to a route, to take advantage of more standard Flask structure; however, since the app currently implements no additional Fluidthere is not currently any plans to duiding
-
dash_covid19.layouts.init_layouts(dash_app: dash.dash.Dash, df: pandas.core.frame.DataFrame, cols: List[str]) → Tuple[dash.dash.Dash, Dict[str, Any]]¶ Initialise layouts and return default
This function is called with create_app() to initialise the app layout in accordance with Flask Application Factory principles.
- Parameters
dash_app (dash.dash.Dash) – A dash app instantiated with dash.Dash()
df (pd.DataFrame) – The data to be used with the app
cols (List[str]) – The columns from df that can be selected for plottint throught the app
- Returns
Containing two objects:
- dash_appdash.dash.Dash
The passed in Dash app with the layouts initiated
- layoutsDict[str, Any]
The dictionary containing the various href: layout key pairs
- Return type
Tuple
Function: init_callbacks¶
Module: Callbacks
To comply with the Flask Application factory layout - as Dash apps are really just Flask apps under the hood - this function initialises the callbacks for the app.
-
dash_covid19.callbacks.init_callbacks(dash_app: dash.dash.Dash, layouts: Dict[str, Any], df: pandas.core.frame.DataFrame) → None¶ Initialise callbacks
This function is called with create_app() to initialise the app callbacks in accordance with Flask Application Factory principles.
- Parameters
dash_app (dash.dash.Dash) – A dash app instantiated with dash.Dash()
layouts (Dict[str, Any]) – Dictionary containung href: layout pairs
df (pd.DataFrame) – The data to be used with the app
- Returns
- Return type
None