Created
December 3, 2024 02:35
-
-
Save dtmilano/41a8c45d9e17c663bb970ab318cec96c to your computer and use it in GitHub Desktop.
Streamlit scroll to bottom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bn/env streamlit run | |
import random | |
import streamlit as st | |
import streamlit.components.v1 as components | |
def content(): | |
for i in range(50): | |
st.write(f"line {i}: {random.randint(0, 1000)}") | |
html_code = f""" | |
<div id="scroll-to-me" style='background: cyan; height=1px;'>hi</div> | |
<script id="{random.randint(1000, 9999)}"> | |
var e = document.getElementById("scroll-to-me"); | |
if (e) {{ | |
e.scrollIntoView({{behavior: "smooth"}}); | |
e.remove(); | |
}} | |
</script> | |
""" | |
st.subheader("Content") | |
if st.button("Scroll to bottom"): | |
content() | |
components.html(html_code) | |
else: | |
content() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment