When I serve the code locally using Vite and run the example.py file, it works as expected. In other words, when I have _RELEASE = False in __init__.py and run npm run dev and streamlit run example.py I get the following output:
However, when I compile the files with npm run build, switch to _RELEASE = True and run the example file again, the component itself doesn’t render and after a couple os seconds an error appears:
Inspecting the browser, it shows that it failed to load both the javascript and the css compiled files. Somehow it cannot find them. But I checked their paths and they seem to be ok.
Go to the repository root directory, create a new Python virtual environment, activate it and install Streamlit and the template as an editable package:
I also checked if the compiled files are working. According to Vite’s documentation:
Once you’ve built the app, you may test it locally by running npm run preview command.
npm run build
npm run preview
The vite preview command will boot up a local static web server that serves the files from dist at http://localhost:4173 . It’s an easy way to check if the production build looks OK in your local environment.
So, with the release flag still set to True, I changed __init__.py line 41 from:
path=build_dir
To:
url="http://localhost:4173"
And the component worked perfectly again. It’s important to note that this method is not meant as a production server. Thus, this is not a solution to the problem, I still need to know how to serve properly from path=build_dir.
I had a very similar problem recently, so not sure if this thing will work for you or not but I did this for rendering react with vite inside streamlit.
add a console.log(window.location.href) inside your app.tsx file, this will print something a url: http://localhost:8501/component/.... now go to your vite.config.ts and inside that add this /component/... url in the public path, and this will work:
this above explanation is for the reactjs, but you can modify it for vue.js.
one problem you might face is the initial rendering of the react goes to 404 page, like not the base url so I am still figuring out the solution for this.
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.