Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Dash overwriting self in class methods

Hi all,

We’re trying to port an app onto Dash but are having a bit of trouble. One issue I haven’t found a workaround for is using dash within class definitions ----
eg
‘’’
class Example:
def init(self):

@app.callback(Output('comp-id', 'value'), [Input('interval-id2', 'n_intervals)])
def foo(self):
    return self.bar()

‘’’
I get an error that ‘int’ self has no attribute ‘bar()’. Is there a way to support self in callback definitions or have dash ignore it?? or better yet, mix dash params with ordinary params?

The self parameter will not be self when called by dash, it will be the n_interval. If you need a ref to self when registering callbacks, you can register the callbacks in a factory method.

Example:

def register_callbacks(self, app):
    @app.callback(...)
    def foo(n_interval):
        return self.bar()