Hello, my current need is to specific location in a page following a click of a button. I have tried implementing a basic scrolling to the top using the below JS, but it is non functional in Streamlit.
import streamlit as st
from streamlit.components.v1 import html
# JavaScript code
my_js = """
<script>
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
</script>
"""
# HTML and JavaScript
my_html = f"""
{my_js}
<button onclick="scrollToTop()">Scroll to the Top</button>
"""
# Execute your app
st.title("JavaScript Example")
# Add some content to make the page scrollable
for i in range(50):
st.write(f"Line {i+1}")
# Use components.html to render the HTML and JavaScript
html(my_html, height=50)