Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

resize handler resets a graph's width, even if that width was explicitily provided #355

@chriddyp

Description

@chriddyp

https://community.plot.ly/t/how-to-fix-plot-width-in-dash/14944

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go

app = dash.Dash(__name__)

app.layout = html.Div(
    children=[
        dcc.Input(id='input', type='text'),
        html.Div(dcc.Graph(id='plot', style={'width': 1000, 'overflowY': 'scroll'})),
        ])

@app.callback(
    Output('plot', 'figure'),
    [Input('input', 'value')]
)
def update_graph_1(input):
    return {'data':[go.Bar(
            x=['Feature A', 'Feature B', 'Feature C',
               'Feature D', 'Feature E', 'Feature F',
               'Feature G', 'Feature H', 'Feature I',
               'Feature J', 'Feature K', 'Feature L',
               'Feature M', 'Feature N', 'Feature O',
               'Feature P', 'Feature Q', 'Feature R',
               'Feature S', 'Feature T', 'Feature U'],
            y=[20, 14, 23, 25, 22,
               20, 14, 23, 25, 22,
               20, 14, 23, 25, 22,
               20, 14, 23, 25, 22, 33])],
            'layout': go.Layout(width=3000)}

if __name__ == '__main__':
    app.run_server(debug=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions