-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python files as static assets ? #425
Comments
Hi, thank you.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>stlite app</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@stlite/mountable/build/stlite.css"
/>
</head>
<body>
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/npm/@stlite/mountable/build/stlite.js"></script>
<script>
async function main() {
const scriptUrl = "https://gist.githubusercontent.com/whitphx/850a985c1db91744b04f24fcde1a5637/raw/022df00377b5e78329879a30c21dda55dc35720a/streamlit_hello_world.py";
const scriptContent = await fetch(scriptUrl).then(res => res.text());
stlite.mount({
files: {
"streamlit_app.py": scriptContent,
},
entrypoint: "streamlit_app.py"
},
document.getElementById("root")
);
}
main();
</script>
</body>
</html> |
thanks for your reply ! Actually, I've just found a workaround:
Et voila ! PS: I noticed from the console in debug mode that the task "setting the loggers" takes quite a while, not sure if it's an expected behaviour. |
That's good. Then I imagine your case is there are so many source files that you don't want to either embed all of them into
Thank you. It is an expected behavior, but I admit its log label is confusing. |
Exactly. As for a more convenient way to do it, maybe something like what pyscript provides for local python modules would be nice, but even with pyscript It seems it's limited to individual modules (but I might be wrong, haven't checked thoroughly). By using a proper packaging approach like my workaround, you get all the benefits that comes with it, including dependency management, embedding of data assets or other resources (ref to #426). So I am not sure it would be worth the hassle, considering also that it's quite straight forward to make it work. So personnaly, I think I would be fine with my approach. |
Thank you for your great suggestion. How about the new stlite.mount(
{
entrypoint: "streamlit_app.py",
files: {
// 👇 This signature is already available.
"streamlit_app.py": `
import streamlit as st
from .data import some_func
st.write(some_func())
`,
// 👇 This is a new API to download a remote file `./data.py` to the local `data.py`.
"data.py": {
url: "./data.py"
},
},
archives: [
// 👇 Downloads an archive file from a URL `./some_package.tar.gz` and unpack it into `.`.
{
url: "./some_package.tar.gz",
dest: ".",
}
]
},
document.getElementById("root")
);
If you want to take the advantage of the Wheel packaging like what you said such as dependency management, stlite.mount(
{
entrypoint: "streamlit_app.py",
requirements: [
// 👇 Set the wheel file URL.
"https://yoursite/your/package.whl"
],
files: {
"streamlit_app.py": `
import streamlit as st
from .data import some_func
st.write(some_func())
`,
},
},
document.getElementById("root")
); BTW, |
I think these would be great additions !
My use case had some dependencies, so I did the latter trick. But without deps, I would definitely go with the Just a couple of questions:
Thanks ! |
Thank you, I hope it solves many problems.
Yes, but not limited to it.
Currently it may be no because the requirement list will be passed to |
Thank you for the answers. I'd personnaly consider the relative URLs in Though I am a bit confused about whether it's already feasible in |
Thank you, hmm, I think it didn't work when I tested roughly, but there might be something wrong. I think the details will be revealed during the development ✌️ |
@JCapul I would be interested to see the example of #425 (comment) if there is a pointer to an open-source copy you are able to share. No worries if not as your description is ultimately quite clear! Thank you! @whitphx #425 (comment) sounds like a very helpful feature set! Thank you! |
The |
Hi @whitphx
Awesome project ! Thanks.
Is there a way to have streamlit python files as static assets, instead of embedding them in the HTML file ?
The text was updated successfully, but these errors were encountered: