Is it possible for code to detect whether the browser is on a phone or small display?
There is a table in our app which seen from mobile looks terrible. We would like to detect if mobile browser is active, and reorganize rows into cards that you can swipe down conveniently.
Is there a variable we can use in the code to know the environment the code is being executed on so we can tailor the UX to it?
from streamlit_javascript import st_javascript
from user_agents import parse
.....
main()
ua_string = st_javascript("""window.navigator.userAgent;""")
user_agent = parse(ua_string)
st.session_state.is_session_pc = user_agent.is_pc
st.info(st.session_state.is_session_pc)
user_agent.is_pc returns True if the session runs on a PC. I then used that to conditionally render some data or not if the User is not running from a PC.
Can also potentially help to prevent the execution of your Streamlit Apps by Bots or other automatic agents.