Can you scale the dcc.Graph height automatically to content?

I have a horizontal bar chart with a dynamic number of bars, could be anything from 10 to 300. Rather than force the user to zoom and move, I’d like the graph to grow in height along the number of bars. The default is 450px I think, and the bars seem to scale to fit in there.

I tried style={‘height’:'auto} on the dcc.Graph but it didn’t do anything. I guess it’s not that simple because if the bars are already auto width/height according to parent container size then that one must be absolute.

As a Python developer who’s new at Dash my second guess would be to pass a variable of len(df.index) multiplied by an arbitrary number of pixels for each bar and add guesstimate for margins, axis, text, title… :roll_eyes: I don’t like it.

How do I achieve this best?

You’ll have to compute the height dynamically. Perhaps 5-10 px per bar. You don’t need to compute the margins though, you can use automargin

Thanks!
With hundreds of bars it looks like it works, didn’t test it with few bars though.

Was it OK to add “automargin=True” with figure.update_yaxes( ... , automargin=True)"?