Hello I’m very new to streamlit. I wanted to know if there is the possibility to load a custom component without using an iframe. This is the component i want to import.
I’ve pip installed the component but when I import it I see that in the DOM it is placed inside an iframe, is it possible to to import it wihout an iframe maybe by loading it manually?
Can someone guide on the steps I need to take in order to achieve this?
I think that I first need to clone the repo and import the function that create the component but is it the best practice?
Ah okay. Well streamlit’s custom components are built using iframe. If you want a non-iframe solution, perhaps build an out of the box solution using st.html or st.markdown. The issue though is passing the data to streamlit which will require some interaction with javascript (i.e. the use of st.components.v1).
What is the problem with the iframe? Is is the space it takes up? You can target it via
st.html( '''
<style>
div:has(iframe[title='title_of_component']){
height:0px;
/* OR */
display:none;
}
</style>
''')
or
st.markdown( '''
<style>
div:has(iframe[title='title_of_component']){
height:0px;
/* OR */
display:none;
}
</style>
''', unsafe_allow_html=True)
Using display may prevent the component from being displayed in your app.
I am having the same problem. I would like to write a very trivial component that displays some custom HTML and when user clicks on it, it passes what got clicked on into Streamlit. The only way I found out how to do that was creating essentially an entire separate website that gets loaded using iframe, which ideally gets bundled using webpack and minified and comes with its own CSS and html… which is neat, but I don’t really care for all the extra complexity.
I can write out html using st.html, but while that is not iframed, it does not support javascript.
I would essentially need three things:
way to inject JavaScript with my HTML
way to pass Streamlit object into my javascript, so I can call methods on it
the API I would use would simply return whatever state my javascript passes out to Streamlit. I am imagining api like this:
st.custom_component(‘html chunk’, ‘javascript chunk’) → returns whatever the javascript set the state to…
Ideally a simple component with little HTML and little javascript is few lines of python code, as opposed to python + node + bundling + deploying + dependency + etc etc etc. I do not mean to use this to make some high quality components, more like “scratch an itch” putting together some simple quick hacks.
I think being able to do such a thing would go well with the otherwise extreme simplicity of using Streamlit that I greatly enjoy!
I think that dealing with data that changes is really an hassle. Is it secure to call some python function from the components? I’m concerned about potential exploits from the client side
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.