Streamlit view full screen

Streamlit indicates altair chart. At this point, when streamlit’s view full screen function is used, the altair chart ratio is completely broken and a horizontal long graph is displayed. I want to maintain the existing ratio, what should I do?

Hi @eric_l,

Please check out our guidelines on posting in the forum and update your post to include a runnable code snippet and a link to your app.

I can’t release the code due to security issues, but if I use the full view screen function even though I did it the way below, the ratio will be broken.
The method below uses the st.altair_chart (plot, use_container_width=True) use_container_width function.

Please share a minimal reproducible example/code snippet (doesn’t need to be your full app) so we can try to reproduce this issue.

@Caroline
I’ll share the code. I expressed altair as streamlit, but if I do a view full screen, the ratio is all broken, not the width and height that I set, so it comes out horizontally long.

chart = alt.Chart(df).mark_circle().encode(x=alt.X(‘count()’,title =None),
y=alt.Y(‘df_y:N’,title=None, sort=‘-x’),
color=alt.Color(‘df_y:N’),
tooltip=[‘count():Q’]
).transform_filter(
brush
).properties(
height=500,
width=450
)

st.altair_chart(chart, use_container_width=True)

Hey @eric_l,

That code snippet isn’t runnable, but I think I get what you’re saying – when the chart is full-screen, the ratio is different because the size of the chart is changed to fit the full window size.

Unfortunately, I don’t know of a workaround to keep the aspect ratio the same when you make an altair chart full-screen – with bokeh charts, for example, the bokeh library allows you to set an aspect ratio, and Streamlit will respect that aspect ratio even if you make the bokeh chart full-screen. It doesn’t seem like altair provides a way to similarly set an aspect ratio (based on this GitHub issue here).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.