have a streamlit app that i want to embed into it javascript i already add html tags by using st.markdown() and i was able to add some bootstrap but when i tried to add javascript code above the html tags it crashes.
import streamlit as st
from streamlit.components.v1 import html
# Define your javascript
my_js = """
alert("Hola mundo");
"""
# Wrapt the javascript as html code
my_html = f"<script>{my_js}</script>"
# Execute your app
st.title("Javascript example")
html(my_html)
Piece of advice: debugging javascript from streamlit is haaaaard. Work it out in a separate html, be sure it’s working, and just then copy the code back to streamlit! Chrome’s Developer Tools can be helpful, too.
(If anyone knows a better method, please advice!)
The HTML method does not send back data to Python as it only displays a static render (Doc Components API). To be honest it could be feasible to hack your way through it through JS hacks that basically revolve on rebuilding the full bidirectional function from the template, which is a bit sad
FYI, I extended the ideas in that post to make the initialization and eventing mechanisms more explicit. To demo that I implemented a simple toggle button component. Much of the JS part is easily re-useable as scaffolding in your own components.
I’m trying to integrate a Stripe pricing table. (Embeddable pricing table for SaaS businesses | Stripe Documentation). I’ve use the components api and tested with both html and iframe. Stripe’s pricing table renders, however, the buttons on the pricing table do not redirect to Stripe payment portal.
In the Stripe documentation listed above, Stripe suggests that the pricing table will not work without allow-top-navigation enabled in the embedded iframe.
I am unsure if this is my issue, but I am hosting on EC2 (i.e. not Streamlit cloud) and would like to test this functionality. Is it possible to write allow-top-navigation into the component?