Callback that takes components with "arbitrary" value types

Hi Dash Community:

I understand that we can use the pattern matching callback for arbitrary or dynamic matched callbacks.
https://community.plotly.com/t/dash-v1-11-0-release-introducing-pattern-matching-callbacks/37592/3
However, is there a way that we can create a component that can support “any” type of input, or a component whose “value” can be of a dictionary?
As a concrete example, I have implemented a UI component, which can takes various type of inputs as below, and the callback takes the value of this component ( as a dictionary ) and perform the calculation accordingly. Right now, there is no simple way other than defining this input one and two as two components ( with different ids ). Apologize if I didn’t express clearly. Thank you.
input one: {“type”: “fruit”, “quantity”: 100, “name”: apple"}
input two: {“date”: today(), “choice”: “English”}

Hello @entropy_l,

This is rather vague.

Do you have a use-case that you can explain or something that you want to achieve?

A dcc.Store can handle objects, arrays, string, integers, Boolean. :stuck_out_tongue_winking_eye:

1 Like

ha, indeed, @jinnyzor. Thank you. Currently, the workaround I am using is indeed dcc.Store.

Here is an example.
Suppose I want to implement a timeseries analysis tool using Dash. In this tool, I have a user input panel that takes inputs of various types. This panel can be made of several html components, and take various inputs. Eventually, they can be translated input program inputs as:
a) {regression_type: “OLS”, start_date: 2021/1/1, end_date: 2023/1/1, indepdent_variable: x, dependent_variable: y}
b) {plot_type: “scatter_plot”, x_variable: x, y_variable: y}
c) {outlier_type: “large_change”, outlier_threshold: 0.1}

In the normal implementation of callback, I will have to do:
[
Input(type_a_regression_type, “value”),
Input(type_a_start_date, “value”),
Input(type_a_end_date, “value”),
Input(type_a_independent_variable, “value”),
Input(type_a_dependent_variable, “value”),
Input(type_b_plot_type, “value”),
Input(type_b_x_variable, “value”),
Input(type_b_y_variable, “value”),
Input(type_c_outlier_type, “value”),
Input(type_c_outlier_threshold, “value”),
]

If keep adding new input types, the callback input list can grow and definitely this is not the ideal way. Eventually, the better way maybe:
[
Input(regression_inputs, “value”),
]
where the value is a “dictionary” and the code logic can handle different input types (a, b, c as the example above ).
As mentioned, I was using the dcc.Store as a workaround, but may not do it in the most correct way but what you replied ignites me.
If you have more thoughts or better design for situation like this, please let me know. Thank you. If useful I can provide code snapshot as well.

1 Like

Hi @entropy_l

I think the dcc.Store may be the best solution. But you could also checkout flexible callback signatures in the docs:

1 Like