Open chriddyp opened 6 years ago
Let's not forget the security concerns raised in #262 :)
A customer suggested having access to an automatically user-scoped dict of some sorts.
Dash-auth could for example provide a user-scoped Store in each callback. It wouldn't need to be saved in the DOM at all - could be Redis backed or fallback transparently to in-process memory if Redis not available.
Shiny has something like this but I haven't investigated it yet.
If any official solution(s) require redis, 'rolling our own' wrappers seems like a good idea...that way we can better ensure a consistent API/experience across languages. Also, FWIW, R has a low-level interface to redis and I doubt many folks would want to work with it directly (for one, R objects must be serialized manually).
For A1 - Allowing Multiple Outputs in a callback would remedy many (all?) of these issues. It's also the easiest to grok as there are no intermediate steps.
That would solve a lot of other issues also, not only related to hidden divs. And isn't it a bit straightforward? Instead of updating one output with result of the wrapped function, unpack list of outputs and apply it to all?
It could still be done in multiple callbacks on front side, just calculate result of the function in Python once as it is the most expensive task.
As #149 is pretty old and long awaited I think implementing it for users in any way, and then polishing it in the back of Dash keeping the interface would make sense.
While allowing multiple outputs would help in some respects with sharing data between callbacks, it doesn't solve the use case of saving "derived state" (as hidden divs allow as described in A3)
There's mention of using session data from Flask. I posted something about in the community forum as I've had a use case for that.
I found that server side session data implemented in Flask-sessionstore works better since it made sense not too pass data back and forth between client and server in my case.
I'd also add that another thing to account for is the support for data that might not be easily serializable. Flask sessions require json serializability, while the server-side sessionstore doesn't (presumably because it doesn't need to be transported)
If there was a nice global dict object, then users could figure out how to assign items on a per-user basis to it, e.g. dash.datastore[dash.user_id] = some_dataframe(dash.user_id)
This made me thing of the Flask Request Contect and Application Context.
I wonder if a global context mechanism like these could be used, or if we could potentially even piggy backing off them, since Dash is already tied to Flask.
I have used json format to transfer dataframe. This method is breaking my app. It works good at start then after 30 seconds it start to lag then my computer freezes. Any solution for this.? I have also tried SQL format, but because of this I am format I am losing information like name of attributes are replaced by numbers. Any solution for this one too?
@T4rk1n is this one still relevant or do we have more recent solutions?
Currently, there are several ways to share data between callbacks. These are outlined here: https://dash.plot.ly/sharing-data-between-callbacks
Some users find these methods complex or clunky and others have trouble understanding which method is best for them.
Let's discuss some ways that we can improve this aspect of Dash.
How Are Hidden Divs Being Used? A1. To store intermediate state that is expensive to generate (in time, # of connections to e.g. a database, in CPU) and to use that intermediate state in several callbacks
How Is Memoization Caching Being Used? B1. Like A1, except persisting the data across all user sessions, perhaps with a time expiring cache
def layout
function and used as the memoization keyHow Could These Methods Be Improved?
For A1 - Allowing Multiple Outputs in a callback would remedy many (all?) of these issues. It's also the easiest to grok as there are no intermediate steps.
For A2 and B1 - Easier Serialization would reduce friction. This is the #1 issue that I hear encounter: confusion around serializing and deserializing JSON or even inability to do so (with complex data structures).
pickle
instead so that serialization and deseralization "just works"?Store
component could handle all types of objects:df = df.read_csv
it'sdf = get_data()
andget_data
is a complex decorated function (see the solution in https://dash.plot.ly/sharing-data-between-callbacks)global dict
but is in fact saving to Redisglobal dict
object, then users could figure out how to assign items on a per-user basis to it, e.g.dash.datastore[dash.user_id] = some_dataframe(dash.user_id)
For A2 and B1 - Faster Serialization
There's some more stuff to discuss here, but this is as far as I've gotten in exploring this problem space today.
cc @plotly/dash