example of how to use react components with streamlit
cd custom_components
npm create vite@latest
- select react (typescript, no swc)
cd <name>
npm i
npm i streamlit-component-lib
- Go to
vite.config.ts
- Add
base: "./"
todefineConfig
- (OPTIONAL) add a server port for dev environment
- Decide wether you want one
__init__.py
per component or one for all components (see init.py for what i mean) - Edit your Component as classes (!)
- Make sure to provide the right path etc in your init.py of choice
- Use in your streamlit app.
There is one example (Table) where you have a sub-folder
frontend
for your react code, and one where you don't (Counter). See what fits you best (or find your own) and continue that way.
❗ To see how to make things reactive, see the Counter example❗
- One for all: Everything at one place
- One for each: easier dev-setup