How to add vertical scroll bar on horizontal bar chart?

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

3 Likes