Dash-extensions, ServerSideOutput error

Hi Emil, I just installed new dash 2.9.3 and the code doesn’t work. so frustrated, The error is shown below. any idea why it is not working for me? Thanks

nvalidCallbackReturnValue: The callback for [<ServersideOutput store.data>, <ServersideOutput time.data>]
returned a value having type DataFrame
which is not JSON serializable.

The value in question is either the only value returned,
or is in the top level of the returned list,

            and has string representation
            `       rnd

0 0.67604`

            In general, Dash properties can only be
            dash components, strings, dictionaries, numbers, None,
            or lists of those.

Hi @roudan,

Did the same callback work before installing the latest version of dash?

Are you sure you used DashProxy and ServersideOutputTransform

app = DashProxy(transforms=[ServersideOutputTransform()])

Could you post a MWE demonstrating the issue? :slight_smile:

I’m getting the same error with 2.9.2 - it used to work fine, I’m returning a list of dataclasses. I refactored the code into pages (https://dash.plotly.com/urls) and now ServersideOutput is trying to json serialise the dataset.

I figured out how to reproduce this, if you define the callback as

@dash.callback(ServersideOutput(component_id='data-store', component_property='data'),
              Input(component_id='dropdown', component_property='value'))
def load_data(id):
    pass

It produces the error, if you replace @dash.callback with @app.callback

@app.callback(ServersideOutput(component_id='data-store', component_property='data'),
              Input(component_id='dropdown', component_property='value'))
def load_data(id):
    pass

It works fine.

Yes, that is expected behavior. You must use imports from ‘dash-extensions’ (instead of ‘dash’) for the transforms to be applied. It has always been like that, there should be no changes with Dash 2.9 :slight_smile:

The docs for multi-page dash apps suggest we use @dash.callback instead of @app.callback to remove the circular dependency where app has to import each page (therefore each page can’t import app to create the callback). What is the dash_extensions.enrich equivalent for this?

I have a single page that needs server side callbacks. At the top of the file, I call dash.register_page() and I have several @dash.callbacks() defined. I already replaced Output, Input, State, and other dash objects with the dash_extensions.enrich versions, but am not sure how the replace the dash object for the pages system.

Like for the objects, simply replace the import of the decorator, i.e. instead of dash.callback, it would be dash_extensions.enrich.callback. Or you could import the decorator at the top,

from dash_extensions.enrich import callback

...

@callback(...)
def some_callback(...):
1 Like