Black Lives Matter. Please consider donating to Black Girls Code today.

Clientside callback example with .js function throws “cannot read property ‘apply’ of undefined” error

I’ve tried to use the cannonical examples given for the clientside callbacks using a js function.

The code I’m using is exactly the one prescribed:

import dash
from dash.dependencies import ClientsideFunction, Input, Output, State
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash(__name__)

app.layout = html.Div(children=
        dcc.Input(id='input', value='hello world'),
        html.Div(id='output - clientside'),
        html.Div(id='output - serverside')

    Output('output - serverside', 'children'),
    [Input('input', 'value')])
def update_output(value):
    return 'Server says “{}”'.format(value)

    output=Output('output - clientside', 'children'),
    inputs=[Input('input', 'value')],
    clientside_function = ClientsideFunction(
        function_name ='display'

if __name__ == '__main__':

The display.js function sits in the /assets folder and is as foolows:

if(!window.dash_clientside) {window.dash_clientside = {};}
window.dash_clientside.clientside = {
    display: function (value) {
        return 'Client says "' + value + '"';

Any help would be welcome since I need to accelerate some of my objects’ rendering by sending them to the client side.

Thanks for reporting @florescorreia. If this doesn’t work then it’s a bug with our docs. Can you print out which versions of dash your using?

These are the ones in this particular environment:


Thanks for your interest and reply.

@florescorreia Sorry for the delay here. I looked into this and you’re correct, this example doesn’t work.

The syntax that you supplied looks out of data from our official documentation: Where did you find this example? I’d like to make sure that it’s updated.

For your particular example, the syntax is this:

window.dash_clientside = Object.assign({}, window.dash_clientside, {
    clientside: {
        display: function (value) {
            return 'Client says "' + value + '"';

Using this syntax works for me with the latest version of Dash.

To be more specific, this particular code block doesn’t work because there is a syntax error - an extra } at the end. This is reported in the browser’s dev tools console:

You can remove this sytnax error and it will work.

Thanks, I tried your solution, but still it does not work – I suspect it’s something on my localhost server (ubuntu 20.04) that I apparently don’t know how to address.
However, the example works just fine when I embed the js code in the callback like this:

    function(value) {
        return 'Client says:: "' + value + '"';
    output = Output('output - clientside', 'children'),
    inputs = [Input('input', 'value')],