# Changing Dash app layout depending on Database value

**URL:** <https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792>\
**Category:** Dash Python\
**Created:** [May 2, 2020, 5:01pm UTC](https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792 "2020-05-02T17:01:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MBKS16](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@MBKS16](https://community.plotly.com/u/MBKS16)\
**Post date:** [May 2, 2020, 5:01pm UTC](https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792/1 "2020-05-02T17:01:05Z")

</div>

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 :

```auto
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?

---

<div class="post-metadata">

**Author:** ![Emil](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emil/32/31734_2.png) [@Emil](https://community.plotly.com/u/Emil)\
**Post date:** [May 2, 2020, 6:00pm UTC](https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792/2 "2020-05-02T18:00:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MBKS16](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@MBKS16](https://community.plotly.com/u/MBKS16)\
**Post date:** [May 2, 2020, 9:00pm UTC](https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792/3 "2020-05-02T21:00:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Emil](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emil/32/31734_2.png) [@Emil](https://community.plotly.com/u/Emil)\
**Post date:** [May 2, 2020, 9:13pm UTC](https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792/4 "2020-05-02T21:13:12Z")

</div>

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](https://dash.plotly.com/live-updates)

---

<div class="post-metadata">

**Author:** ![MBKS16](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@MBKS16](https://community.plotly.com/u/MBKS16)\
**Post date:** [May 2, 2020, 9:55pm UTC](https://community.plotly.com/t/changing-dash-app-layout-depending-on-database-value/38792/5 "2020-05-02T21:55:32Z")

</div>

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