Change width of sidebar

Hi there,

I would like to show an image in the sidebar. Like this, the image can be viewed while scrolling through the app.

Can the width of the sidebar be increased such that the complete image is visible in a reasonable size? It is possible to set the width of the image to make it smaller but this makes it difficult to read information from the image.

Any help is very much appreciated!

Cheers, Lili

2 Likes

Hi!

I am having the same problem, but I want to print a small table (5 columns) onto the sidebar without scrolling right.

@thiago How can we do it?

Thanks!

Hi @lnros . There is currently no official way to set the sidebar width, but if you search the forums youโ€™ll find some hacks people have created.

In the meantime, please follow this feature request I just created so youโ€™re notified if/when we implement this! https://github.com/streamlit/streamlit/issues/2058

1 Like

I was able to change the sidebar width this way:

st.markdown(
    f'''
        <style>
            .sidebar .sidebar-content {{
                width: 375px;
            }}
        </style>
    ''',
    unsafe_allow_html=True
)

It does work @Larrypc, but it messed up sidebar UI, even after collapsing it, we can still see it.

you can modify the width of the expanded sidebar by using the css selector โ€œsection[data-testid=โ€œstSidebarโ€] .css-ng1t4oโ€ and set the width appropriately. The default width is 21rem

st.markdown(f'''
    <style>
    section[data-testid="stSidebar"] .css-ng1t4o {{width: 14rem;}}
    </style>
''',unsafe_allow_html=True)
1 Like

This solution worked in dark mode. Iโ€™ve made an addition which lets it work in light mode as well:

st.markdown(f'''
    <style>
        section[data-testid="stSidebar"] .css-ng1t4o {{width: 14rem;}}
        section[data-testid="stSidebar"] .css-1d391kg {{width: 14rem;}}
    </style>
''',unsafe_allow_html=True)
3 Likes

can we do it for st.selectbox also?