Skip to main content

A plugin to print Dash app errors on the header section of the page

Project description

Dash Error Plugin Demo

A Dash plugin to display callback errors in your Dash app.

Installation

pip install callback-error-plugin_demo_8

Usage

from dash import Dash, html, dcc, Input, Output, State, callback
from callback_error_plugin_demo_8 import error_banner_component, register_error_banner_callbacks

app = Dash(__name__)

# Create a customizable error banner
show_error = register_error_banner_callbacks(
    banner_id="my-error-banner",
    text_id="my-error-text",
    dismiss_id="my-dismiss-button",
    default_text="Custom error will display here.",
    color="white",
    background="#b71c1c",
    border_color="#f44336",
    z_index=9999,
    position="top",
)

def hide_error_banner():
    show_error("")

app.layout = html.Div(
    [
        # Place the error banner at the top
        error_banner_component(
            banner_id="my-error-banner",
            text_id="my-error-text",
            dismiss_id="my-dismiss-button",
            default_text="Custom error will display here.",
            color="white",
            background="#b71c1c",
            border_color="#f44336",
            z_index=9999,
            position="top",
        ),
        html.Div(
            [
                html.H2(
                    "Division Calculator",
                    style={"textAlign": "center", "fontSize": "2.2rem"},
                ),
                html.Label(
                    "Enter a number:",
                    htmlFor="input-number",
                    style={"fontSize": "1.3rem"},
                ),
                dcc.Input(
                    id="input-number",
                    type="number",
                    value=1,
                    style={
                        "fontSize": "1.3rem",
                        "width": "100%",
                        "marginBottom": "1rem",
                        "marginTop": "0.5rem",
                        "padding": "0.5rem",
                        "borderRadius": "6px",
                        "border": "1px solid #ccc",
                    },
                ),
                html.Button(
                    "Calculate",
                    id="calc-btn",
                    style={
                        "width": "100%",
                        "fontSize": "1.2rem",
                        "marginTop": "1rem",
                        "padding": "0.5rem",
                        "borderRadius": "6px",
                        "backgroundColor": "#6c757d",
                        "color": "white",
                        "border": "none",
                    },
                    n_clicks=0,
                ),
                html.Div(
                    id="output-div",
                    style={
                        "fontSize": "1.4rem",
                        "marginTop": "2rem",
                        "minHeight": "2.5rem",
                        "textAlign": "center",
                    },
                ),
            ],
            style={
                "maxWidth": "400px",
                "margin": "80px auto 0 auto",  # 80px top margin for the banner
                "boxShadow": "0 2px 12px rgba(0,0,0,0.08)",
                "borderRadius": "12px",
                "backgroundColor": "#f9f9f9",
                "fontFamily": "Segoe UI, Arial, sans-serif",
                "padding": "32px",
            },
        ),
    ]
)

@callback(
    Output("output-div", "children"),
    Input("calc-btn", "n_clicks"),
    State("input-number", "value"),
)
def update_output(n_clicks, value):
    hide_error_banner()
    if n_clicks == 0:
        return ""
    if value is None:
        show_error("Please enter a number!")
        return ""
    if value == 0:
        show_error("Division by zero is not allowed!")
        return ""
    result = 10 / value
    return f"The result is {result}"

if __name__ == "__main__":
    app.run(debug=True)

Running the Example

python app.py

Notes

  • The error banner will appear at the top of your app when you call show_error("Your message").
  • You can customize the error message, color, and style by changing the arguments to error_banner_component and register_error_banner_callbacks.
  • The plugin handles showing and hiding the error banner for you.

Enjoy building with Dash!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

callback_error_plugin_demo_8-0.0.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

callback_error_plugin_demo_8-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file callback_error_plugin_demo_8-0.0.2.tar.gz.

File metadata

File hashes

Hashes for callback_error_plugin_demo_8-0.0.2.tar.gz
Algorithm Hash digest
SHA256 076c9c5226f87a304e05b661b35d922319e2334631cee9542a29387b3d81b69f
MD5 b4390ebee86d9e6a3fa8aefbf40329cf
BLAKE2b-256 b61acd271d814e650b4dab4096605ece8573318ced8f6ac940c3e83cd35e7f64

See more details on using hashes here.

File details

Details for the file callback_error_plugin_demo_8-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for callback_error_plugin_demo_8-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8cc92968785c9109b79028213ec28a6a0685f7e6dd41e1f82e2e0eb13f50533
MD5 73b728b2a83795e1027d8cc54cb421ae
BLAKE2b-256 0205928b86cbeb1a5a5af06a3943679287744b89011fe1fa520515b49d4dd0b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page