Validation of Callback Inputs throws an Error on dynamically generated props

Hi,

the task i´d like to achive is the following:
The Application is some industrial linux pc and it has a python script for control logic and one python dash script for a dashboard. I want to send values from the control script to callbacks of the dash script. (a polling aproach using dcc.Inverval is what i like to avoid)

my solution so fare:
A custom dash component that has a websocket and communicates via json strings.
This first part seams to work fine. Now for simplicity and easy use i like to split the callback in “topics”.

A example would be:
incomming json via websocket-> {“value1”:3.1415, “value2”:42} → and each value update should have its own callback

the problem i’m facing now is that since i generate the props “value1” and “value2” dynamically they will throw a error on property check at the beginning page initialisation. (never the less the concept seams to work fine after the error messages)

I´d be very happy about feedback on solving this issiue but also on any other solution that might be already existing on my task.

here is the screenshot and example code for my approach:

import dash_varex
from dash import Dash, callback, html, Input, Output

app = Dash(
        name,
        suppress_callback_exceptions=True,
        )
app.layout = html.Div(
        [
               dash_varex.DashVarex(
                        id=“varex”,
                        value=“my-value”,
                        label=“my-label”,
                        websocketUrl=“ws://192.168.0.100:8765”,
                        topics=[“value1”, “value2”],
                ),
                html.Div(id=“value1”, children=“Latest update of value1:”),
                html.Div(id=“value2”, children=“Latest update of value2:”),
                html.Div(id=“connected”, children=“Connection Status:”),
        ]
)

@callback(
Output(“value1”, “children”),
Input(“varex”, “value1”),
)
def display_value1(value):
       return “Send Value to value1:”, value

@callback(
Output(“value2”, “children”),
Input(“varex”, “value2”),
prevent_initial_call=True,
)
def display_value2(value):
       return “Send Value to value2:”, value

@callback(Output(“connected”, “children”), Input(“varex”, “is_connected”))
def display_output(value):
       return “Connection Status:”, value

if name == “main”:
app.run(debug=True)

Thanks a lot for any suggestions!

Hey @Tobias_And,

I am not sure if I understood this completely but it sounds like you could benefit from pattern matching callbacks.

Have you seen these already?

Thx @AIMPED for the Feedback!

i made some experiments with the ALL pattern matching callback but i did not manage to avoid the initial layout check that is veriving the properties.

But i realised when the component is not part of the initial layout but is loaded later on with a callback there is no property check. That is a ok solution for me right now, since that is what the actual production dashboard will do anyhow.

1 Like