Long_callback with list of States and Outputs doesn't work

Hi! I have this code and it works fine

@app.callback([Output('SELL_vs_BUY_graph', 'figure'),
               Output("button_calculate_SELL_vs_BUY", 'n_clicks'),
               Output("text_SELL_vs_BUY", "children")],
              [Input("button_calculate_SELL_vs_BUY", 'n_clicks')],
              [State('input_database_name_SELL_vs_BUY', 'value'),
               State('input_day_SELL_vs_BUY', 'value'),
               State('partial_time_SELL_vs_BUY', 'value'),
               State('number_of_levels_SELL_vs_BUY', 'value'),
               State('step_size_of_level_SELL_vs_BUY', 'value'),
               State('time_SELL_vs_BUY', 'value'),
               State('save_SELL_vs_BUY', 'value'),
               State('partials', 'children')]
              )
def sell_vs_buy_graph(button_calculate, database_name, input_day, user_partial_time,
                      number_of_levels, step_size_of_level, time_depth_om, save, partials):
    pass

But I would like use long_callback, unfortunately, documentation is poor in this regard (1, 2)
I would like use something like this:

@app.long_callback(
    output=[Output('SELL_vs_BUY_graph', 'figure'),
     Output("button_calculate_SELL_vs_BUY", 'n_clicks'),
     Output("text_SELL_vs_BUY", "children")],
    args=(Input("button_calculate_SELL_vs_BUY", 'n_clicks'),
    [State('input_database_name_SELL_vs_BUY', 'value'),
     State('input_day_SELL_vs_BUY', 'value'),
     State('partial_time_SELL_vs_BUY', 'value'),
     State('number_of_levels_SELL_vs_BUY', 'value'),
     State('step_size_of_level_SELL_vs_BUY', 'value'),
     State('time_SELL_vs_BUY', 'value'),
     State('save_SELL_vs_BUY', 'value'),
     State('partials', 'children')]),
    running=[
        (Output("button_calculate_SELL_vs_BUY", "disabled"), True, False),
    ],
    progress=[Output("progress_bar", "value"), Output("progress_bar", "max")],
)

But i get errors: dash.exceptions.CallbackException: Inputs do not match callback definition
Or TypeError: sell_vs_buy_graph() missing 9 required positional arguments: 'button_calculate', 'database_name', 'input_day', 'user_partial_time', 'number_of_levels', 'step_size_of_level', 'time_depth_om', 'save', and 'partials'. I have tried a lot of different options, because i can’t find documentation how to write code in my case. Can anybody help me, please?

With

    output=[Output('SELL_vs_BUY_graph', 'figure'),
     Output("button_calculate_SELL_vs_BUY", 'n_clicks'),
     Output("text_SELL_vs_BUY", "children")],
    inputs=(Input("button_calculate_SELL_vs_BUY", 'n_clicks')),
    states=(State('input_database_name_SELL_vs_BUY', 'value'),
     State('input_day_SELL_vs_BUY', 'value'),
     State('partial_time_SELL_vs_BUY', 'value'),
     State('number_of_levels_SELL_vs_BUY', 'value'),
     State('step_size_of_level_SELL_vs_BUY', 'value'),
     State('time_SELL_vs_BUY', 'value'),
     State('save_SELL_vs_BUY', 'value'),
     State('partials', 'children')),

I lose my state parameters with sell_vs_buy_graph function
(TypeError: sell_vs_buy_graph() missing 8 required positional arguments: 'database_name', 'input_day', 'user_partial_time', 'number_of_levels', 'step_size_of_level', 'time_depth_om', 'save', and 'partials')

If i use dash-labs

import dash_labs as dl
## Diskcache
import diskcache
cache = diskcache.Cache("./cache")
long_callback_manager = dl.plugins.DiskcacheCachingCallbackManager(cache)
app = dash.Dash(__name__,  plugins=[
    dl.plugins.FlexibleCallbacks(),
    dl.plugins.HiddenComponents(),
    dl.plugins.LongCallback(long_callback_manager)
])

i get error

Traceback (most recent call last):
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\intensity_graphs\run_dash.py", line 19, in <module>
    import dash_labs as dl
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash_labs\__init__.py", line 1, in <module>
    from . import plugins
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash_labs\plugins\__init__.py", line 1, in <module>
    from .pages import page_container
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash_labs\plugins\pages.py", line 14, in <module>
    raise Exception("A folder called `pages` does not exist.")
Exception: A folder called `pages` does not exist.

If i use

@app.long_callback(
    [Output('SELL_vs_BUY_graph', 'figure'),
     Output("button_calculate_SELL_vs_BUY", 'n_clicks'),
     Output("text_SELL_vs_BUY", "children")],
    [Input("button_calculate_SELL_vs_BUY", 'n_clicks')],
    [State('input_database_name_SELL_vs_BUY', 'value'),
     State('input_day_SELL_vs_BUY', 'value'),
     State('partial_time_SELL_vs_BUY', 'value'),
     State('number_of_levels_SELL_vs_BUY', 'value'),
     State('step_size_of_level_SELL_vs_BUY', 'value'),
     State('time_SELL_vs_BUY', 'value'),
     State('save_SELL_vs_BUY', 'value'),
     State('partials', 'children')],
    running=[
        (Output("button_calculate_SELL_vs_BUY", "disabled"), True, False),
    ],
    progress=[Output("progress_bar", "value"), Output("progress_bar", "max")],
)

I get error

2021-12-26 10:55:30,234 - ERROR - Exception on /_dash-update-component [POST]
Traceback (most recent call last):
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash\dash.py", line 1303, in dispatch
    args_grouping = map_grouping(
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash\_grouping.py", line 130, in map_grouping
    return {k: map_grouping(fn, g) for k, g in grouping.items()}
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash\_grouping.py", line 130, in <dictcomp>
    return {k: map_grouping(fn, g) for k, g in grouping.items()}
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash\_grouping.py", line 132, in map_grouping
    return fn(grouping)
  File "C:\Users\dvernad\PycharmProjects\Students\Stock_exchange\env\lib\site-packages\dash\dash.py", line 1304, in <lambda>
    lambda ind: inputs_state[ind], inputs_state_indices
IndexError: list index out of range

By some reason i get variable state = [{'id': '_long_callback_store_1', 'property': 'data', 'value': {'pending_job': 13752, 'pending_key': '48edd32c22f61647a879fafe988e6fee3035b3e4'}}] in dash.dispatch function

Thats magic, current version started work fine!!
A few moments later… :joy:
That seems like it very unstable tool, sometimes i get this error:

raise SchemaTypeValidationError(value, full_schema, path, expected_type)
dash._grouping.SchemaTypeValidationError: Schema: {'user_callback_output': [<Output `SELL_vs_BUY_graph.figure`>, <Output `button_calculate_SELL_vs_BUY.n_clicks`>, <Output `text_SELL_vs_BUY.children`>], 'interval_disabled': <Output `_long_callback_interval_1.disabled`>, 'in_progress': [<Output `button_calculate_SELL_vs_BUY.disabled`>], 'progress': [<Output `progress_bar.value`>, <Output `progress_bar.max`>], 'user_store_data': <Output `_long_callback_store_1.data`>}
Path: ('user_callback_output',)
Expected type: (<class 'tuple'>, <class 'list'>)
Received value of type <class 'NoneType'>:
    None

I changed

[Output('SELL_vs_BUY_graph', 'figure'),
 Output("button_calculate_SELL_vs_BUY", 'n_clicks'),
 Output("text_SELL_vs_BUY", "children")],

to

(Output('SELL_vs_BUY_graph', 'figure'),
 Output("button_calculate_SELL_vs_BUY", 'n_clicks'),
 Output("text_SELL_vs_BUY", "children"))

Hope that it will be helpfull for other developers :slight_smile:
A few hours later… :neutral_face:
By some reason my new callback works twise, oh, it’s very difficult to integrate long_callback
Deleting Output(“button_calculate_SELL_vs_BUY”, ‘n_clicks’) helped me, but i don;t understand why