I suggest that we add something like the following line in the Dash User Guide page on Layouts:
“The instantiation of app.layout must not be placed inside of the conventional if __name__ == __main__ otherwise the layout will not be detected when the app is deployed.”
This happened to me as I was making my first Dash app. I instantiated my app.layout inside of
if __name__ == __main__
The sneaky thing about this particular issue, is that the app works when you run it locally, but results in an Internal Server Error when deployed (I was deploying to Heroku).
The Officiall Dash User Guide should be something that a first-time Dash learner can completely follow, resulting in his/her first successful Dash App without going through a troubleshooting headache. I believe this will help ensure that first time Dash learners who are learning from the User Guide will avoid the incident I had endured.
Technically, the User Guide never tells me to put app.layout inside of if __name__ == __main__ but the reason I tried to put it in there was that in some python code styles and conventions, all code that is not meant to run when a python file is imported is placed inside of if __name__ == __main__. Well, I thought that wasn’t the case for instantiating app.layout, but it turns out it is.
1 post - 1 participant