whitphx / stlite Goto Github PK
View Code? Open in Web Editor NEWServerless Streamlit ππ
Home Page: https://edit.share.stlite.net
License: Apache License 2.0
Serverless Streamlit ππ
Home Page: https://edit.share.stlite.net
License: Apache License 2.0
Low priority because;
Like
Great work! I have tried using my code and noticed that st.line_chart doesnt work.
@stlite/desktop
It would be nice to just give the url to an existing streamlit app (python code) hosted on github, as we normally do with Streamlit Cloud.
Great work!
During development with yarn start
in packages/playground
, when new changes are saved and the page is hot-reloaded, stlite-kernel is reloaded but Streamlit frontend stays disconnected.
It should reconnect when the kernel restarts.
Apart the WebSocket communication, Streamlit also uses many HTTP endpoints for various purposes including serving media files and custom component resources.
To make use of these existing HTTP endpoints and the corresponding client implementations with a minimum amount of changes, it looks like ServiceWorker is a good way, compared to re-implementing these communications on top of WebWorker messaging.
Does st.download works with stlite? I added a download button to my streamlit app using st.lite but it doesn't work.
Run stlite on Cloudflare workers some PaaS where NodeJS can run such as fly.io or adaptable as a server-side process and serve the page like normal Streamlit.
It may be kind of simpler than stlite on browsers as the necessary part may be patching Tornado to run and handle HTTP req/res on the workers and the upstream Streamlit may run on it without modifications.
UPDATE: Cloudflare Workers are not for such usage as its worker function is expected to run in a short time like 10ms, and even on a paid plan, 30mins.
UPDATE2: Cloudflare Workers doesn't limit the duration: https://developers.cloudflare.com/workers/platform/limits/#duration
We can use https://github.com/pyodide/pytest-pyodide
The upstream Streamlit removed tornado.gen
: streamlit/streamlit#4895
Support inputting multiple Python files that are imported from the main script file.
The mountable API would be like this?
This is more general design that covers not only Python scripts but also other types of files.
stlite.mount({
entrypoint: "streamlit_app.py",
files: {
// Python files
"streamlit_app.py": `
import streamlit as st
...
`,
"pages/page1.py": `
# This is the first page.
`,
"pages/page2.py": `
# This is the second pae.
`,
// Other files, e.g. data files
"data/foo.csv": // Text file
`id,name
1,Bob
2,Alice
`,
"data/secret.dat": new ArrayBuffer(/* Some data */), // Binary file
"models/foo.h5": fetch("...") // Support async API?
"models/compressed.h5": {
url: "....zip",
unpack: true. // Unpack the archive: https://pyodide.org/en/stable/usage/faq.html#how-can-i-load-external-files-in-pyodide
}
}
})
Reported at https://discuss.streamlit.io/t/new-library-stlite-a-port-of-streamlit-to-wasm-powered-by-pyodide/25556/3
The source code copied:
import streamlit as st
import time
st.set_page_config(
page_title='Pomodoro',
layout='centered',
page_icon='π
'
)
def count_down(ts):
with st.empty():
while True:
mins, secs = divmod(ts, 60)
time_now = '{:02d}:{:02d}'.format(mins, secs)
st.header(f"{time_now}")
time.sleep(1)
ts -= 1
if ts < 0:
break
st.write("Time Up!")
st.balloons()
def main():
st.title("Pomodoro")
time_minutes = st.number_input('Enter the time in minutes ', min_value=0.1, value=25.0)
time_in_seconds = time_minutes * 60
if st.button("START"):
count_down(int(time_in_seconds))
if __name__ == '__main__':
main()
It may hit performance? First, measure it!
It looks like just to set some value to the server.fileWatcherType
config:
https://github.com/streamlit/streamlit/blob/1.13.0/lib/streamlit/config.py#L505
It raises an error such as
6.8fc22a8b.chunk.js:1 TypeError: Cannot read properties of undefined (reading 'embed')
at BokehChart.tsx:109:13
at BokehChart.tsx:123:5
at Ls (6.8fc22a8b.chunk.js:1:1608317)
at t.unstable_runWithPriority (6.8fc22a8b.chunk.js:1:1626130)
at qi (6.8fc22a8b.chunk.js:1:1548488)
at Ns (6.8fc22a8b.chunk.js:1:1607778)
at 6.8fc22a8b.chunk.js:1:1607689
at B (6.8fc22a8b.chunk.js:1:1625189)
at E.port1.onmessage (6.8fc22a8b.chunk.js:1:1623911)
Multi-line log messages emitted from Python runtime are split into single lines and displayed with different console.log()
calls.
Multiple lines from a single log source should be aggregated and displayed with a single console.log()
.
It uses threading
that is not supported in the Pyodide environment and raises an exception, RuntimeError: can't start new thread
.
RuntimeError: can't start new thread
Traceback:
File "/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 555, in _run_script
exec(code, module.__dict__)
File "/home/pyodide/streamlit_app.py", line 10, in <module>
with st.spinner():
File "/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/lib/python3.10/site-packages/streamlit/__init__.py", line 441, in spinner
_add_script_run_ctx(_threading.Timer(DELAY_SECS, set_message)).start()
File "/lib/python3.10/threading.py", line 928, in start
_start_new_thread(self._bootstrap, ())
Note: time.sleep()
is no-op on Pyodide, so awaiting would be a bit tricky.
Currently, if some error occurs before the Streamlit server launch, the screen stays "Loading...".
It should indicate the error.
The copy-and-pasted code in stlite-tornado
is growing, so it should be replaced with the upstream Git repository and some patches on it.
To use at
By making it as a web-compatible extension, we will be able to use it on GitHub Codespaces which realizes the true in-browser development experience.
PyZQM includes C-extension files that we need to build specifically for Pyodide.
blinker 1.5 now has a pure Python package (*py3-none-any.whl
).
https://pypi.org/project/blinker/1.5/#files
Pandas-related components such as st.table
or st.line_chart
are using PyArrow to pass the data from the server to the frontend, but PyArrow is not working.
PyArrow includes C-extension that we need to build specifically for Pyodide.
getBuffer
for the needs of ndarray.Provide a single (or maybe multi) JS file that developers can embed with script tag and just works.
Page not found
You have requested page /stlite, but no corresponding file was found in the app's pages/ directory. Running the app's main page.
This seems to be derived from upgrading Streamlit to 1.10.0: #40 and its multipage app functionality.
A common use case would be installing packages with micropip
https://github.com/whitphx/stlite/pull/83/files#diff-4c5eecd52e82d618b38158b716aa037b0d15179e3bfd4d9d726e33aae4b110ceR157
but, XSRF seems not necessary for stlite?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.