-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add main application and configuration files for Dash app
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Main Application File""" | ||
|
||
import dash | ||
from dash import Output, Input, dcc, html | ||
from appconfig import appconfig | ||
|
||
# Initialize the Dash app | ||
app = dash.Dash(__name__) | ||
|
||
# Define the layout of the app | ||
app.layout = html.Div( | ||
children=[ | ||
html.H1(children="Hello Dash"), | ||
html.Div( | ||
children=""" | ||
Dash: A web application framework for Python. | ||
""" | ||
), | ||
dcc.Input(id="input-text", value="initial value", type="text"), | ||
html.Div(id="output-text"), | ||
] | ||
) | ||
|
||
|
||
# Define callback to update the output text | ||
@app.callback( | ||
Output(component_id="output-text", component_property="children"), | ||
[Input(component_id="input-text", component_property="value")], | ||
) | ||
def update_output_div(input_value): | ||
return f"You've entered: {input_value} and {appconfig.DASH_APP.APP_TITLE}" | ||
|
||
|
||
# Run the app | ||
if __name__ == "__main__": | ||
app.run_server(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""This module reads the configuration file and converts it to a namespace.""" | ||
|
||
import tomllib | ||
from types import SimpleNamespace | ||
|
||
def dict_to_namespace(d): | ||
"""Convert a dictionary to a namespace.""" | ||
for key, value in d.items(): | ||
if isinstance(value, dict): | ||
d[key] = dict_to_namespace(value) | ||
return SimpleNamespace(**d) | ||
|
||
with open('config.toml', 'rb') as f: | ||
config_dict = tomllib.load(f) | ||
|
||
appconfig = dict_to_namespace(config_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[DASH_APP] | ||
APP_TITLE = "MTA DASH" | ||
HEAD_TITLE = "taruma-mtadash | MTA DASH" | ||
UPDATE_TITLE = "Updating..." | ||
DEBUG = false | ||
ALIAS = "taruma-mtadash" | ||
|
||
[TEMPLATE] | ||
WATERMARK_SOURCE = "" | ||
THEME = "MATERIA" | ||
|
||
VERSION = "v1.2.0" | ||
GITHUB_LINK = "https://github.com/taruma/anfrek" | ||
GITHUB_REPO = "taruma/anfrek" |