Observations. When scrip/javascript is inside a st.html it just NEVER got rendered to the page (streamlit v. 1.40).
st.markdown() at least puts the code to the page, but the alert i put there for testing NEVER gets triggered at all.
Thanks @Goyo for clarifying about st.html … but i found a bunch of answers here using st.markdown like in the example above. And that injects it fine, but it doesnt get executed at all.
I don’t remember seeing working examples of that, but it isn’t mentioned in the docs either, so I don’t have a clear answer to that. If you con find a working example, compare it to yours and try to figure out what the relevant difference is. I will take a closer look at it when /if I have time.
As mentioned, st.html doesn’t support JS, but you can use streamlit.components.v1 (here’s a demo, wait for a few seconds and you’ll see the alert popping up)
import streamlit as st
import streamlit.components.v1 as components
st.title("JS demo")
components.html("""
<script>
alert("Hello from javascript")
</script>""")