admin管理员组文章数量:1417045
Problem Description
I'm integrating a custom JavaScript component with a Streamlit application. When I run app.py, the app displays an error message in the browser indicating it cannot load the my_folder_uploader component due to potential network latency or proxy settings.
Error message
Your app is having trouble loading the app.my_folder_uploader component. If this is an installed component that works locally, the app may be having trouble accessing the component frontend assets due to network latency or proxy settings in your app deployment. For more troubleshooting help, please see the Streamlit Component docs or visit our forums.
Dir Structure
my_streamlit_component/
├── frontend/
│ ├── build/ # Webpack output directory
│ ├── src/
│ │ └── MyComponent.jsx
├── package.json
├── webpack.config.js
├── .babelrc
└── app.py # Streamlit application
Code Snippet
app.py
import streamlit as st
import streamlitponents.v1 as components
_component_func = components.declare_component(
"my_folder_uploader",
path="frontend/build" # Ensure this path points to the correct build directory
)
def my_folder_uploader():
files = _component_func()
return files
st.title("Folder Uploader")
uploaded_files = my_folder_uploader()
if uploaded_files is not None:
st.write("Uploaded files in the folder:")
for file in uploaded_files:
st.write(file)
MyComponent.jsx
// MyComponent.jsx
import React, { useCallback } from "react";
import ReactDOM from "react-dom";
import { withStreamlitConnection, Streamlit } from "streamlit-component-lib";
const FolderUploader = () => {
const handleFiles = useCallback((event) => {
const files = event.target.files;
const fileArray = Array.from(files).map(file => file.webkitRelativePath);
Streamlit.setComponentValue(fileArray);
}, []);
return (
<div>
<h1>Folder Uploader</h1>
<input type="file" webkitdirectory="true" onChange={handleFiles} />
</div>
);
};
const ComponentWithConnection = withStreamlitConnection(FolderUploader);
ReactDOM.render(<ComponentWithConnection />, document.getElementById("root"));
Environment Information
Python v3.12.6 Node.js v22.13.1 React v17.0.2 Webpack v5.97.1 Babel v5.8.38 Windows 11
What I've Tried
Cleared the browser cache. Rechecked Webpack configuration. Ensured the React component is correctly mounted.
Expected Outcome
The custom JavaScript component should render correctly within the Streamlit app page and allow users to select a folder for upload.
本文标签:
版权声明:本文标题:javascript - Streamlit app is not displaying the custom component due to frontend asset loading issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745265083a2650551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论