Skip to content

Commit

Permalink
Add main application and configuration files for Dash app
Browse files Browse the repository at this point in the history
  • Loading branch information
taruma committed Nov 7, 2024
1 parent c68fcec commit 67e733f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app.py
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)
16 changes: 16 additions & 0 deletions appconfig.py
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)
14 changes: 14 additions & 0 deletions appconfig.toml
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"

0 comments on commit 67e733f

Please sign in to comment.