Basically I want to make the device vibrate on certain occasions, and haven’t been able to find a reliable way to execute the script consistently.
This is my sample function:
st.markdown(
"""
<script>
function vibrate() {
navigator.vibrate(1000)
}
</script>
""",
unsafe_allow_html=True
)
This is how I’m trying to call it using the streamlit-javascript package just as a test:
if st.button("Vibrate"):
js_code = """vibrate()"""
res = st_javascript(js_code)
This does nothing.
If I try and skip the middleman like this:
if st.button("Vibrate"):
st_javascript("""navigator.vibrate(1000)""")
It doesn’t work either but exhibits the following behaviour: If I click it a lot of times in quick succession it briefly vibrates, but not for the specified amount of time.
Basically my question is:
- How can I vibrate the device using Streamlit?
- If there is no easy solution, how can I run any JS script reliably out of Streamlit (so I can vibrate)