You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Dash objects reset their height to 450px after changing tabs #922
This problem started after I upgraded to dash 1.19.0 (possibly a dash-core-components 1.15.0 issue??)
I have an app with multiple tabs, with dash components on them like charts and indicators. I set the component heights using update_layout. When I first load the page, everything looks fine. But when I click on a different tab, and then go back to the previous tab, all the dash charts and indicators change their height to 450px. The indicators are set in my code to be 200px, and when they snap to 450px after changing tabs, the indicators components themselves stretch outside of their containing DIVs.
Can confirm this was not an issue in Dash 1.16 and was recently introduced.
As well as getting this on a backlog for a fix in future release, I'm also interested if anyone has a clever workaround to prevent this right now while using the current dash version.
Thanks,
Nathan
Reacted by Jeremy Grifski, Justin B, James Knight and _Naza_
Thanks for the report @gtg489p - can you make a self-contained example app that shows the problem? There are a number of ways to set sizes so it's important that we're talking about the same thing.
I can try for a full fledged example when time allows, but for the time being - to address your specific concern, here is how I set the height of the figures in my python code
fig.update_layout(height=200)
It is set once at initialization, and no callbacks ever touch it again.
Thanks @AnnMarieW , I'll see to using that in the mean time (changed 200 to "200px")
Off topic, but how did you create that gif illustrating the bug? I know there are gif maker programs out there but just wondering if there's a commonly accepted way. Thanks
I'm not sure about the commonly accepted way to make a gif, but on Linux I use Peek and on Windows I used ScreenToGif. Both are pretty simple, which makes them easy to use.
Any other workaround on this? Setting the height in the dcc.Graph does not work for me as I want to have different dcc.Graph and figure heights (and using 'overflowY': 'scroll').
@ann-marie-ward thanks for this workaround. It works for me but is clunky to have to specify the height by style when my dcc.Graph objects (a plotly Table and a line_mapbox) already specify height via their height parameters.
In my case, my two tabs initially render correctly, click to the second one, good. Click back to the first, and the height changes to 450px. This is using 1.21. If I add your style parameter to both dcc.Graph objects, it works correctly.
Same problem here! The workaround works well though, thanks @AnnMarieW . But a fix would be good since now I am styling both the figure and graph in two places, when one should be enough
This issue happened when I changed one tab (showing a heatmap with default aspect ratio) to another tab (showing a bar chart). I tried the style parameter workaround as suggested:
but still to no avail. I noticed that this issue only happens when I changed tabs from the heatmap tab, and the tab with issue is the subsequent tab from heatmap tab (where I am using px.imshow.
So I added the aspect='auto' parameter in px.imshow so that it follows the size of plot area. Now it works fine.
Here's a way to solve it.
I used @AnnMarieW 's code for this example.
Just added a Callback that uses the dcc.Tabs value as input to set the size of the graph everytime you switch tabs.
It uses the current state of both graphs to transform it into a go.Figure (from plotly.graph_objects) and sets the layout's height you need.
It just causes a little blink in the chart and you can see how it changes sizes, but is only just a microsecond, so, if it's not a major problem for you, it works :)
Here's an example of a clientside callback for faster updating if your graph takes a while to create and specifying the height in style isn't a solution for you. Note that also specifying the height in the dcc.Graph style will likely overwrite the callback output.
The dcc.Tabs components has id='tabs', the dcc.Graph has id='plot' and the dcc.Graph is inside tab 1 with default value='tab-1'. The updated graph will have a height of 450px.
The graphs on each of my tabs have a variable height that is calculated based on the len of the df in the callback. The height varies widely depending on the value selected from the dropdown. In this case, setting a fixed height is not an option. I don't think any of the proposed workarounds will work for my case.
Here's a way to solve it. I used @AnnMarieW 's code for this example. Just added a Callback that uses the dcc.Tabs value as input to set the size of the graph everytime you switch tabs. It uses the current state of both graphs to transform it into a go.Figure (from plotly.graph_objects) and sets the layout's height you need.
It just causes a little blink in the chart and you can see how it changes sizes, but is only just a microsecond, so, if it's not a major problem for you, it works :)
Activity
alexcjohnson commentedon Jan 26, 2021
Thanks for the report @gtg489p - can you make a self-contained example app that shows the problem? There are a number of ways to set sizes so it's important that we're talking about the same thing.
gtg489p commentedon Jan 27, 2021
I can try for a full fledged example when time allows, but for the time being - to address your specific concern, here is how I set the height of the figures in my python code
fig.update_layout(height=200)
It is set once at initialization, and no callbacks ever touch it again.
Thanks,
Nathan
AnnMarieW commentedon Jan 27, 2021
Here is a small app that shows the problem. It's a new issue in 1.19.0. It works fine in 1.18.1
alexcjohnson commentedon Jan 27, 2021
Thanks @gtg489p and @AnnMarieW - moved to dcc as that's ultimately where the problem is. This is probably a result of #905
AnnMarieW commentedon Jan 27, 2021
Hey @gtg489p
A workaround is to add the height in the style parameter of dcc.Graph:
This works with 1.19.0
gtg489p commentedon Jan 28, 2021
Thanks @AnnMarieW , I'll see to using that in the mean time (changed 200 to "200px")
Off topic, but how did you create that gif illustrating the bug? I know there are gif maker programs out there but just wondering if there's a commonly accepted way. Thanks
AnnMarieW commentedon Jan 28, 2021
@gtg489p Happy to help :-)
I'm not sure about the commonly accepted way to make a gif, but on Linux I use Peek and on Windows I used ScreenToGif. Both are pretty simple, which makes them easy to use.
ppfreitas commentedon May 28, 2021
Any other workaround on this? Setting the height in the dcc.Graph does not work for me as I want to have different dcc.Graph and figure heights (and using 'overflowY': 'scroll').
nhoover commentedon Sep 11, 2021
@ann-marie-ward thanks for this workaround. It works for me but is clunky to have to specify the height by style when my dcc.Graph objects (a plotly Table and a line_mapbox) already specify height via their height parameters.
In my case, my two tabs initially render correctly, click to the second one, good. Click back to the first, and the height changes to 450px. This is using 1.21. If I add your style parameter to both dcc.Graph objects, it works correctly.
Admolly commentedon Oct 7, 2021
Experiencing the same problem as ppfreitas. Having another workaround/fix would be nice!
mcsewhoy commentedon Nov 17, 2021
Same problem here! The workaround works well though, thanks @AnnMarieW . But a fix would be good since now I am styling both the figure and graph in two places, when one should be enough
jo47011 commentedon Jan 18, 2022
Is this issue solved in Dash 2.x?
daviddavo commentedon May 22, 2022
No, it's still not solved
yuenherny commentedon Aug 20, 2022
This issue happened when I changed one tab (showing a heatmap with default aspect ratio) to another tab (showing a bar chart). I tried the style parameter workaround as suggested:
but still to no avail. I noticed that this issue only happens when I changed tabs from the heatmap tab, and the tab with issue is the subsequent tab from heatmap tab (where I am using
px.imshow.So I added the
aspect='auto'parameter inpx.imshowso that it follows the size of plot area. Now it works fine.I am using:
lnkov commentedon Sep 2, 2022
Experiencing same bug. Switching tabs resets height of Dropdown options container, previously set by maxHeight argument.

Lxstr commentedon Sep 6, 2022
I'm still having this issue as my charts are dynamic heights based on internal variables.
IsraelCea commentedon Nov 17, 2022
Here's a way to solve it.
I used @AnnMarieW 's code for this example.
Just added a Callback that uses the dcc.Tabs value as input to set the size of the graph everytime you switch tabs.
It uses the current state of both graphs to transform it into a go.Figure (from plotly.graph_objects) and sets the layout's height you need.
It just causes a little blink in the chart and you can see how it changes sizes, but is only just a microsecond, so, if it's not a major problem for you, it works :)
WhatsApp.Video.2022-11-17.at.17.37.49.4.mp4
MitchMedeiros commentedon May 27, 2023
Here's an example of a clientside callback for faster updating if your graph takes a while to create and specifying the height in style isn't a solution for you. Note that also specifying the height in the dcc.Graph style will likely overwrite the callback output.
The dcc.Tabs components has
id='tabs', the dcc.Graph hasid='plot'and the dcc.Graph is inside tab 1 with defaultvalue='tab-1'. The updated graph will have a height of 450px.Use
allow_duplicate=Truein the Output if the dcc.Graph is created through another callback. Otherwise you should be okay to remove it.chivonblanton commentedon Sep 7, 2023
The graphs on each of my tabs have a variable height that is calculated based on the len of the df in the callback. The height varies widely depending on the value selected from the dropdown. In this case, setting a fixed height is not an option. I don't think any of the proposed workarounds will work for my case.
Any ideas in this case?
cscadenas commentedon Apr 8, 2024
In case anyone else is facing the same issue, and to complete a bit this answer, I managed to avoid the blink by having the tab content outside the Tab component, as in this example:
https://dash-bootstrap-components.opensource.faculty.ai/examples/graphs-in-tabs/
I have only tried it with dbc.Tabs and not with dcc.Tabs, so I don't know if it'd solve the issue. In any case I think it can be useful.
Cheers