Changing Dash app layout depending on Database value

I would like to change my Dash app layout depending on a value that I read from a database (Firebase Realtime Database in my case) . Thus, it will look something like :

app = dash.Dash()

//retreive database value 

if(databaseValue == thisValue):
	app.layout = this.layout
else:
	app.layout = that.layout

After deploying the app on Heroku and running it for the first time, the layout is set and stays the same even if the database value is changed.
Do you have any ideas?

If you create a function, which determines the layout based on the db value, and assigns it as the app layout, the app should behave as intended.

The issue here, as I mentioned, is that the layout is set when I run the app locally or I push it to Heroku but never changes (in real time) even if the DB value does.
For the changes to be taken into consideration I should then re-run or re-push the app.
Should I use a callback? if so, what should the input/output be?

If you assign a function to the layout variable, it should. Hence if you have a function my_layout, you should do,

app.layout = my_layout

With this syntax (rather than app.layout = my_layout()), the function is evaluated each time, and your layout will thus change depending on the db value. There is some doc at the bottom of this page,

https://dash.plotly.com/live-updates

1 Like

It was indeed a syntax issue. It has worked! thank you so much for your time.