this is my first post in this forum : )
I’ve been using dash for a few months now and have read myself into Dash and tried out several things.
What I still don’t really understand is how to handle callbacks with lots of inputs and outputs.
In addition, there is the limitation that an element can be only once in a callback output. I know one solution
is the MultiplexerTransform from the dash-extensions library.
But anyhow as the code size grows my app gets difficult to maintain.
Therefore to organize my code more efficiently I would like to use classes to preprocess the data and use the callbacks only for trigger and output.
I created the following MWE and would like to know, if this could break in a multi-user environment, e.g. object attributes shared between users unintenionally?
from dash import Dash
from mwe_class import User_Data
app = Dash(__name__)
app.layout = mwe_component.render(app, User_Data())
So, the main reason you are wanting to use classes is because of the limitation of the one callback per output? - This is actually about to change, plotly has been working on removing this limitation.
As far as rendering layouts specific to users, you can do all of that also without classes. You’ll need to have some way to get the users that are logged in. I use flask_login for this.
Now, with the layouts and criss-crossing info, if you use global variables, yes, it is very easy to mess it up. If you avoid those, then the app already operates in a stateless manner, thus keep them separated.
thank you very much for your answer.
Actually I have several input fields which needs calculation and cascading to other elements.
The app will be used locally by few people on a server.
When using my example code, will users get their own class object instance, or is it shared?
In the documentation is an example for a not reliably working code. Has my code the same flaws even if not explicitly using the “global” flag in the callback?
the documentation then says: The callback returns the correct output the very first time it is called, but once the global df variable is modified, any subsequent callback that uses that dataframe is not using the original data anymore.
To improve this app, reassign the filtered dataframe to a new variable inside the callback as shown below, or follow one of the strategies outlined in the next parts of this guide.