# online demo of https://fac.feffery.tech/getting-started
import dash
from dash import html
import feffery_antd_components as fac
from dash.dependencies import Input, Output
# Instantiate the Dash application object
app = dash.Dash(__name__)
# Add initial page content
app.layout = html.Div(
fac.AntdCard(
[
# Input form
fac.AntdForm(
[
fac.AntdFormItem(
fac.AntdInputNumber(id="target-value", style={"width": "100%"}),
label="Target Value",
),
fac.AntdFormItem(
fac.AntdInputNumber(id="actual-value", style={"width": "100%"}),
label="Actual Value",
),
],
layout="inline",
style={"marginBottom": 25, "width": "100%"},
),
# Output target container
html.Div(
id="output-container",
style={
# Using flex layout from CSS for center alignment
"width": "100%",
"display": "flex",
"justifyContent": "center",
"alignItems": "center",
},
),
],
title="Dash + FAC Application Example",
hoverable=True,
style={
# Using fixed layout from CSS
"position": "fixed",
"top": "40%",
"left": "50%",
"transform": "translate(-50%, -50%)",
"width": 630,
"height": 350,
},
)
)
# Define callback function to connect interaction logic
@app.callback(
Output("output-container", "children"),
[Input("target-value", "value"), Input("actual-value", "value")],
)
def handle_progress_render(target_value, actual_value):
# Check if the input target and actual values are valid
if target_value and actual_value:
return fac.AntdProgress(
percent=round(100 * actual_value / target_value, 2), type="dashboard"
)
return fac.AntdResult(
subTitle="Please enter valid target and actual values", status="warning"
)
if __name__ == "__main__":
app.run(debug=False)