How to get the windows size when I run streamlit app

I need to show images or videos in a container, and I hope to change the number in one row depending on the width of container

This library GitHub - aghasemi/streamlit_js_eval: A custom Streamlit component to evaluate arbitrary Javascript expressions has a method for getting parameters like screen.width

See the example in the readme:

st.write(f"Screen width is {streamlit_js_eval(js_expressions='screen.width', key = 'SCR')}")

tks๏ผŒI will try it at once

I am sorry to find, yes, it seems the package has a simple way to get the window size, but I just test, it is not stable, and just show once time seemly the width shown, but when I tried more, the width number didnโ€™t change, I resized my windows once and once ,and then refresh my chrome, after I change my windows, but no useful.

I think what you need is the page window width rather than the screen window width.

import streamlit as st
from streamlit_js_eval import streamlit_js_eval
page_width = streamlit_js_eval(js_expressions='window.innerWidth', key='WIDTH',  want_output = True,)

The method doesnโ€™t automatically rerun when the windows is resized, so if you want to change the app when a window is resized, it might not work well.