-
-
Notifications
You must be signed in to change notification settings - Fork 143
[BUG] Graph(style='height=100%') fails when reducing window size on Firefox #605
Comments
Here is an example showing the problem: import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(
id='body',
style={
'display': 'flex',
'flex-flow': 'column',
'background-color': 'green',
'height': '100vh',
'width': '100%'
},
children=[
html.Div(
id='header',
children=[
html.H1('MWE'),
]
),
html.Div(
id='expand',
style={
'flex-grow': 1,
'height': '100%',
'width': '100%',
'background-color': 'blue'
},
children=[
dcc.Graph(
figure=dict(layout=dict(autosize=True)),
style={
'height': '100%',
},
),
]
),
]
)
app.run_server(debug=True) |
Although the sample example above sort-of-works, in my real-life application it doesn't :-( I have a complex layout using nested flex boxes, specifically a top bar, a side bar, and a main display region which tries to span the remaining space. Things I have seen:
Bottom line: the automatic resize of the graph when the container is at width and height of 100% is too fragile to work for me. I am working around the issue by giving some elements fixed sizes and setting the graph size to something horrible like |
Moved the issue to the |
And @orenbenkiki thanks for opening another very clear and helpful issue! |
@orenbenkiki I too have experienced some frustrations using Flexbox layouts with ...
dcc.Graph(
figure=dict(layout=dict(autosize=True)),
config=dict(responsive=True),
style={
'height': '100%',
},
), Behaviour on Firefox without my suggestion (cut-off x-axis) With my suggestion ( That is, add Does that solve your problem? The documentation for this could probably be higher-profile, sorry about that. There is a section on it here. I also want to echo @alexcjohnson that we appreciate your clear and well-defined issues with examples! |
Possibly these flags do makes things better, but they don't fix my real-world application. Some computation deep in the code looks at "100%" and interprets it as "100px", causing the (very initial) size to be 100 x 100 pixels, which triggers the "something went wrong with axis scaling" error (when computing the colorbar coordinates). I don't have a minimal program to demonstrate this :-( |
Making my way through the comments made above and will provide feedback as I go through them. I am using:
This problem is unrelated to the dcc.Graph, while annoying this is normal browser behavior when making a top-level element take 100% of the viewport and is caused by browsers applying a default style to the In Chrome:
Same in Firefox: https://hg.mozilla.org/mozilla-central/file/tip/layout/style/res/html.css#l122 The scrollbar issue can be replicated by simply using an empty div:
There's really only three ways to handle this:
This seems to be working fine with the versions above. Can you confirm if you still experience this issue?
👀 Looking. More to come. |
Using a slightly more complex UI I get a graph that can grow but can't get smaller in both Chrome and Firefox.
Adding The latest versions of @antoinerg Any insight into the latest comments, what would the next steps be? |
That looks a lot like this plotly.js issue plotly/plotly.js#3034 which was fixed by plotly/plotly.js#3056 . What happens when you turn on the configuration option |
@antoinerg Too fast! I updated the comment above with |
@Marc-Andre-Rivet By setting However, as of right now, with To make this reality, I think we may need a new config option in |
Testing this out with a more complex scenario where the elements themselves can be resized without the window being resized. The graph does not react to these changes.
|
Trying out the following strategy:
|
Got a demo for you guys, hopefully this will help understand the problem, or at least otherwise educate me on what I'm doing wrong. I'm demonstrating with three ways of describing the figure — dash ==1.6.1 import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import plotly.graph_objs as go
from dash.dependencies import Input, Output, State, ClientsideFunction
app = dash.Dash(__name__)
server = app.server
iris = px.data.iris()
div_style = {
# for visual demonstration
'padding': '10px',
'background-color': 'red',
# the key style argument - constrained height containers
'height': '400px'
}
app.layout = html.Div(children=[
html.Div(style=div_style,
children=[
dcc.Graph(
figure={
'data': [{
'x': [1, 2, 3, 4],
'y': [5, 4, 3, 6],
'line': {'shape': 'spline'}
}],
'layout': {'autosize': True},
},
config={'responsive': True},
)
]
),
# layout spacing, for demo purposes only
html.Div(style={'height': '200px'}),
html.Div(style=div_style,
children=[
dcc.Dropdown(
id='flower-dropdown',
options=[
{'label': i, 'value': i} for i in
['Sepal', 'Petal']
],
value='Sepal',
),
dcc.Graph(id='flower-graph',
# will not even respond to 'height': 'inherit'
# *when the figure is returned by a callback*
# not sure if this is px or the callback or both
config={'responsive': True},
style={'height': 'inherit'}
)
]
),
html.Div(style={'height': '500px'}),
html.Div(style=div_style,
children=[
dcc.Graph(
figure={
'data': [
go.Scatter(
x=[1, 2, 3, 4, 5],
y=[4, 3, 1, 5, 1],
line=go.scatter.Line(shape='spline')
)
],
'layout': {'autosize': True},
},
config={'responsive': True},
# this will make the graph respond appropriately
# remove the style argument, and the graph will
# overflow, despite the 'responsive' flag being set
style={'height': 'inherit'}
)
]
),
# style arguments for visual demonstration, no affect on graph dimensions
], style={'background-color': 'green', 'height': '300vh'})
@app.callback(
Output('flower-graph', 'figure'),
[Input('flower-dropdown', 'value')])
def update_output(val):
if val == 'Petal':
x_val = "petal_width"
y_val = "petal_length"
else:
x_val = "sepal_width"
y_val = "sepal_length"
fig=px.scatter(iris,
x=x_val,
y=y_val,
color="species")
fig.update_layout(autosize=True)
return fig
if __name__ == '__main__':
app.run_server(debug=True) |
The third example works, but take note of my comments on the style argument — commenting it out will make the graph overflow. |
@wbrgss Using the code currently in (early) review #706 For this to work and the graph to be bounded to its container, it needs to be styled appropriately, like any other element. The 1st graph needs, for example:
The 2nd graph needs some way to divide the space between itself and the dropdown, this can be achieved for example by adding to the container's style:
|
It is not yet working for python right? |
PIP
Describe the bug
Writing:
Graph(..., style=dict(height='100%'))
Expected behavior
The graph should fill the full height of the
div
, which will obey normal CSS rules, that is, span all the available space in the layout. It should not cause any overflow, and respond to window resize (also on Firefox ;-).Actual behavior
A scrollbar appears for a small amount of overflow (both Chrome and Firefox). Since the amount is small, it is possible to work around this with
overflow=hidden
, but it may cause clipping (e.g. if using long labels for the X axis, etc.).Reducing window size does not cause graph resize (Firefox only). That is strange, one would expect that any resize event is handled the same way, regardless if the new size is higher or lower than the original size.
Edit
The following example almost works, except for the two issues above. This threw me off, originally I thought that the feature does not work at all. I edited the issue title and content accordingly.
The text was updated successfully, but these errors were encountered: