I am trying to add a button to scroll to the top. Something like:
import streamlit as st
import time
st.write('meow ' * 10_000)
js = '''
<script>
var body = window.parent.document.querySelector(".main");
console.log(body);
body.scrollTop = 0;
</script>
'''
if st.button("Back to top"):
temp = st.empty()
with temp:
st.components.v1.html(js)
time.sleep(.5) # To make sure the script can execute before being deleted
temp.empty()
However, it is not scrolling to the top. It reruns the page but stays in the same place. Does someone know how to achieve this?
Edit: I’m using version 1.39.0 and python 3.11.4