Is there a way to horizontally scroll containers?

I see that displaying a dataframe with st.dataframe(df) allows the dataframe to scroll. However, if I’m drawing multiple graphs within individual columns of an expandable, sometimes, the “overrun” the width and get clipped. It would be very helpful in this case, to allow the expandable to horizontally scroll, so that I don’t lose my graphs.

Does such functionality exist?
Here’s a minimal example of what I’m trying to do:

graphs = [some, list, of, graph, data]
with st.expandable("section title"):
    cols = st.columns(len(graphs))
    for col, graph_data in zip(cols, graphs):
        st.altair_graph(my_draw_graph_function(graph_data))
4 Likes

My understanding is that the containers should reorganize and restack to fit the browser width. Is this not working the way you expect?

The grid works just fine - there are n cells packed within the page width. The problem is that each cell has an altair chart in it, and the chart gets truncated/cut/clipped because it is wider than the width of the cell.

I would in fact love to be able to allow the cells to be expanded by the size of their contents (the altair charts in this case) and overflow page-width with a horizontal scrollbar

2 Likes

The only other option I can think of that will immediately allow you to at least view the charts would be to set the Altair charts use_container-width property to true. That should scale them up and down so the whole chart is visible in the allotted width. (however small). I’m not sure how Streamlit decides what width is a good width for viewing and when it starts kicking columns down to subsequent rows.

If you put a feature request in the streamlit github for what you are looking for (scrolling containers), the streamlit team is usually pretty good about considering and responding to feature requests.

I’m not sure that scrolling columns give the best user experience though. Typically, web pages strictly scroll vertically and the content resizes and reforms to explicitly avoid horizontal scrolling.

1 Like

The option “use_container_width=True” only works with a single Altair chart. It failed when I used Altair charts with ‘alt.hconcat’ (combined 2 Altair charts horizontally) - my chart was cut off when browser was resized.

4 Likes