It might be hard to be clear on exactly why it wouldn’t work given that that was aiming towards a solution that wasn’t going to work in general due to the limitation of callbacks having only output. However the bit of information that you might be missing for this to make sense is that you have to define your callback(s) upfront when the app is initialised. If you try to register a callback in response to user input, it won’t do anything. So you either need to define one big monolithic callback handling all inputs or if you need multiple callbacks, every possible one that is needed must be registered upfront.
The reason for passing through n as a keyword argument, is because without doing this, the callback definition creates a closure over the variable n in the top level scope, but that n is getting updated on each iteration of the loop. If we didn’t explicitly pass the variable through, when the callback is executed the variable n inside the callback function would have the value that it recieved in the outer scope on the last iteration of the for loop – ie MAX_PEOPLE. It has to be a keyword argument simply because it would no longer align with the number of arguments Dash derives from the Ouptut and Inputs/State if we tried to pass it in as a positional argument.
I think what I’m enjoying about Dash is I kinda get to do frontend web development in Python… The trick about hiding divs for example is more of a CSS trick that we happen to have access to from within Python code. Such fun 