Custom components
Streamlit custom components extend your app beyond built-in widgets with custom UI elements. V2 components offer better performance and multiple callbacks without iframes, while V1 components run in iframes with single callbacks.
V2 custom components
Backend (Python)
Register
Register a custom component.
my_component = st.components.v2.component(
"my_component",
html=HTML,
js=JS
)
my_component()
Mount
Mount a custom component.
my_component = st.components.v2.component(
"my_component",
html=HTML,
js=JS
)
my_component()
Frontend (TypeScript)
npm support code
Support code published through npm.
npm i @streamlit/component-v2-lib
FrontendRenderer
Type alias for the component function.
import { FrontendRenderer } from "@streamlit/component-v2-lib";
FrontendRendererArgs
Type alias for the component arguments.
import { FrontendRendererArgs } from "@streamlit/component-v2-lib";
FrontendState
Type alias for the component state.
import { FrontendState } from "@streamlit/component-v2-lib";
CleanupFunction
Type alias for the component cleanup function.
import { CleanupFunction } from "@streamlit/component-v2-lib";
V1 custom components
Declare a component
Create and register a custom component.
from streamlit.components.v1 import declare_component
declare_component(
"custom_slider",
"/frontend",
)
This command was deprecated in version 1.56.0. Use
st.iframeinstead, orst.htmlto insert HTML without an iframe.
HTML
Display an HTML string in an iframe.
from streamlit.components.v1 import html
html(
"<p>Foo bar.</p>"
)
This command was deprecated in version 1.56.0. Use
st.iframeinstead.
iframe
Load a remote URL in an iframe.
from streamlit.components.v1 import iframe
iframe(
"https://docs.streamlit.io"
)
Still have questions?
Our forums are full of helpful information and Streamlit experts.