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?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.