Py.Cafe

CNFeffery/

fac-getting-started-demo-en-us

Dash with Feffery Components Demo

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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)