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

Handle data uploaded by user

Hello,

We are building quite an extensive app that allows a user to upload his own set of data to complement the one we provided.

Since the user data must be protected, we plan to store it in a dataframe that would be called based on the user IP retrieved with the help of flask. However this data should exist only as long as the user is connected to the app which is not the case with my solution. On top of that, the data must be accessible through several tabs in our tab.

Is there a better solution to do what I am trying to do and matching my constraints?

Thanks a lot!
PS: that’s just insane what you can do with dash, and so easy to use once you understand callbacks, keep going with the great work!

One way to deal with “sessions” is to assign a user ID in the app.layout on page load. I have an example that’s going to go into the docs here: https://github.com/plotly/dash-docs/pull/84/files

Thanks a lot for the quick answer.

However, I am not quite sure I am understanding properly.
The idea is to attribute to each user a unique session id, that is stored in a hidden div. That means that each sessions should have different hidden div children, am I right? When I am doing this, I find the same session_id for all my sessions.
I used the same layout as yours:

def serve_layout():

    # User specific ID
    session_id = str(uuid.uuid4())
    print(session_id)
    return  html.Div([html.Div(session_id, id='session-id', style={'display': 'none'}),])
app.layout = serve_layout()

Using your example directly, I see the same exact results in both session. Am I missing something obvious?

On top of that, I carry objects instead of dataframe. Would that work too, it seems that you pass it to JSON format and serialize the data.

Finally, I don’t quite get where the data get removed once the session is over. I assume it is hidden in the decorator @cache.memoize(). But since you have one master dataframe containing the data of all user, this dataframe never gets destroyed. What am I missing to understand that point?

thanks a lot !

I am making small progress toward having a solution, however, I am still facing huge problems.

So far, I create a div containing the user IP:

def serve_layout():
    return html.Div([
        html.Div([], id='session-id2', style={'display': 'none'}),
        html.Div([], id='session-id', style={'display': 'none'}),
    ])

app.layout = serve_layout()



@app.callback(Output('session-id', 'children'),
              [Input('session-id2', 'children')])
def get_ip(value):
    return str(request.remote_addr)

The method with str(uuid.uuid4()) was somehow constantly giving me the same ID to each sessions.

The problem I have is that I am using tabs, and need to keep user specific data accessible to each tab.
I already use a global variable that is shared everywhere and modify nowhere so that users do not interacts with each other and that contains data accessible to everyone, the ‘base’ data.
I wish to have a second object containing user specific data that can be passed around.

I tried your method on many attempts but never succeeded to pass it to all Tabs. What would be the best way to do so? Keeping the data in a div, and how would I do that properly? Doing so, I wouldn’t have to use the cache and knowing the IP, right? Is there a better way?

Thanks a lot!

It should be

app.layout = serve_layout