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

Why global code runs twice

In my dash application, there are some pre-processing where I initialize some variables. The codes are placed before app = das.Dash() line. See example.

def get_big_dataframe():
perform a large query.
x = get_big_dataframe()
app = dash.Dash()

However, when I run the app, before starting the server it executes the line x = get_big_dataframe() twice. Do you know why it executes twice? How can I prevent it to execute twice?

This is how flask debugger works. You can set debug=False to prevent this, but then you’ll miss out on the live reloading.


Now I understand the reason. :slight_smile: