Rerun when file system/database/some other external data source changes
See original GitHub issueThis is an issue to cover the topics not addressed within PR https://github.com/streamlit/streamlit/pull/2060 that were raised within the issue https://github.com/streamlit/streamlit/issues/653.
Below are copied in some key comments
The key goals personally for an API that is able to rerun when an external data source changes are listed below:
- Selected module imports
- To support live-reloading while building streamlit apps within the pymedphys library (https://github.com/pymedphys/pymedphys/tree/master/pymedphys/_gui/streamlit).
- Allows for a significantly faster development iteration loop within the framework of a Python library/package.
- Directory updates
- To support deploying a plugin based GUI where pymedphys users can add their own streamlit apps and submit them upstream. The index/landing page of the GUI would live update when new apps are added to the index
- Some key ideas are the following – https://github.com/streamlit/streamlit/issues/543#issuecomment-660410027
- File updates
- To make it so that images collected from our linear accelerator (https://www.elekta.com/radiotherapy/) at work can be live streamed to the application with analysis undergone in real time
- Database triggered updates
- To have changes within our radiation oncology information system (https://www.elekta.com/software-solutions/care-management/mosaiq-radiation-oncology/) automatically trigger app reruns.
_Originally posted by @SimonBiggs in https://github.com/streamlit/streamlit/pull/2060#issuecomment-704016152_
Is there a way to get the current session from within a watchdog thread? For example, see the following use case:
After you create a thread (but before you start it), you can call report_thread.add_report_ctx(...)
to attach a ReportContext object (which contains the session_id) to that thread.
Of course, this requires that thread creation be under your control - which (I think?) does not apply for watchdog.
What I’d suggest in this situation - with the caveat that it’s been a while since I looked at this code - is to create a separate thread (with the ReportContext attached) that simply handles watchdog file-changed events that are raised from within the watchdog thread. (You’ll need to set up some method of communicating between the two threads, like a thread safe queue or something.)
Does that make sense, and is it possible for your use case?
_Originally posted by @tconkling in https://github.com/streamlit/streamlit/pull/2060#issuecomment-703945085_
Some ideas for various possible APIs:
st.experimental_autoreload(modules)
modules
can be an iterable of imported modules (types.ModuleType
) or a single imported module.- Flags it so that any changes in these modules will cause the streamlit app to auto-reload.
- See https://github.com/pymedphys/pymedphys/blob/1995dd1177d6f6b57dbf81dc251092d2ab4e5d9b/pymedphys/_gui/streamlit/dashboard.py#L27 for usage.
st.experimental_file_contents(path)
- Returns the contents of a file and triggers a rerun whenever the contents of that file changes (reusing the same logic as used for autoreload).
– https://github.com/streamlit/streamlit/issues/653#issuecomment-679853730
and
st.experimental_directory_tree('path/to/directory', recursive=False)
- Returns a list of file paths within a given directory, triggers a rerun whenever that directory tree itself changes (file name changed or file added or deleted).
- This would support something like the default
index.py
I described over at https://github.com/streamlit/streamlit/issues/543#issuecomment-660410027
– https://github.com/streamlit/streamlit/issues/653#issuecomment-680423424
_Originally posted by @SimonBiggs in https://github.com/streamlit/streamlit/pull/2060#issuecomment-703901760_
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:12 (5 by maintainers)
Anyone? Thx
Hi. I am currently researching web app frameworks for a new project, so I am new to the topic. Streamlit sounds wonderful and is currently my favorite. However, I absolutely need the “rerun when database (redis keys) changes” feature. I have read #2060 and #2180, but I am not yet sure if the feature is available (per
st.experimental_rerun
).Thank you for a brief info or links to related documentation.