I would like to create unique session ids for each time a user opens the dash app in browser.
I have been following the tutorial here:
https://dash.plot.ly/sharing-data-between-callbacks
This is my code:
import dash
import dash_html_components as html
import dash_core_components as dcc
import flask
import datetime
import uuid
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = flask.Flask(__name__)
dash_app = dash.Dash(__name__,server=app,url_base_pathname="/",external_stylesheets=external_stylesheets)
def serve_layout():
session_id = str(uuid.uuid4())
return html.Div([
html.Div(session_id, id='session-id', style={'display': 'none'}),
html.Div(dcc.Input(id="input_session_id",type="text",value=session_id))
])
dash_app.layout = serve_layout()
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=80)
It seems like the session ids are different if I use different computers but if I use the same computer, it will stay the same.
Is there a way to generate an unique session each time an user opens the url for the dash app?
Obviously problem was in this line: dash_app.layout = serve_layout()
You had to use it without parenthesis:
dash_app.layout = serve_layout
In fact you were assigning not a function, but a result of the function called once at the first page load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With