Need to automatically go at the top of the page

You can inject javascript. Try this, making sure to scroll down before the page loads to observe (that’s why I put the sleep in there). However, the javascript only executes when it is added to the page on first load. I am unclear on your intended use, but if you conditionally remove the javascript so that you can render it from scratch when you need it you can get its effect more than once.

import streamlit as st
import time

st.write('meow ' * 10_000)
time.sleep(3)

js = '''
<script>
    var body = window.parent.document.querySelector(".main");
    console.log(body);
    body.scrollTop = 0;
</script>
'''

st.components.v1.html(js)
7 Likes