How to add vertical scroll bar on horizontal bar chart?

I have a horizontal bar chart that can contain anywhere between 1 and 300 bars depending on selections in a shiny dashboard. When there are many bars being displayed, they are too thin. I would like to set a minimum width to the bar and have a vertical scroll bar to see those which don’t fit on the first page. I can provide an image of the squished bars if the problem is unclear.

thank you!

edit: I am hoping to achieve something similar to this highcharts chart: https://www.highcharts.com/blog/news/224-scrollbars-for-any-axis/

I’ve solved this for anyone who stumbles upon this question in the future.

Put the plotly output in a div container with a max height and overflow-y set to scroll like so:
div(style=‘max-height:500px; overflow-y: scroll; position: relative’,plotlyOutput(“plot”))

In ouput$plot dynamically set the plot height with this:
plot_height <- 500 + 10*nrow(df) where df is the dataframe used to create the plot. the plot has one bar per row in the dataframe, so this scales linearly with the number of records.

Then in plot_ly set the height to plot_height

ian

4 Likes