Declaring callbacks with some non-existing Inputs results in a JS error


#1

I figured out how to solve this, but figured I’d post about it because the initial symptom was this inscrutable error in the console:
Uncaught TypeError: undefined does not have a method named "concat"(…)

I have an app with tabs and buttons. Some buttons appear on one tab, some buttons appear on the other. I’d set up a callback function to be able to use a dynamic number of buttons like:

@app.callback(Output(OUTPUTDIV, 'children'),
              [Input(button_id, 'n_clicks') for button_id in BUTTONS])
def button_clicks(*args):
     for n_clicks in args:
          #do something

It worked fine with one tab, but when I added a second tab, and a second set of buttons, the app broke. No errors were showing up in Python, but the buttons wouldn’t do anything when clicked anymore. Eventually I found the inscrutable error above, but was puzzled, since the Python code would be able to handle if arguments passed to it were None so it took me a while to figure out what was happening.

My solution will be to iterate over the tabs and create a button_clicks() function for each. Maybe this will be a problem for other setups?

I don’t really know what’s happening on the Javascript side, but it would be nice if JS would pass back None values to the callback :slight_smile:


#2

Have you ever gotten that feeling where you search for an issue and find your own post?

This happened again because we’re missing data from a sensor, and the app was still creating an object for that sensor for the most recent period for which we had data. But if the user changes to select their own timeperiod, this sensor object disappears and the callback associated with it breaks a bunch of the app.

I noticed this by having DEBUG logging statements in different callbacks and comparing which ones fire in a good scenario vs. a breaking one.