# streamlit-modal-input
Streamlit component providing a 'modal' text input widget (actually pausing the script until a string is entered and returned). Implemented using the [firebase-user](https://github.com/B4PT0R/firebase_user) package to establish direct communication between the python backend and the React frontend.
It is meant first and foremost as a target widget for stdin redirection in case you wish to embed a live python interpreter in your streamlit app.
Routing the interpreter's output to display widgets is fairly easy, but due to how Streamlit works, redirecting stdin to a widget in the app and achieving the expected blocking behavior was not that simple...
## Installation instructions
```sh
pip install streamlit-modal-input
```
## Usage instructions
This widget is meant to be used with the firebase-user package as follows.
You first declare a firebase user client with your firebase app json configuration file and authenticate your user:
```python
from firebase_user import FirebaseClient
if 'firebase_client' not in st.session_state:
with open("app_config.json",'r') as f:
config=json.load(f)
st.session_state.firebase_client=FirebaseClient(config)
st.session_state.firebase_client.auth.sign_in(user_email,user_password)
```
Then you can call the modal input widget, passing it the authenticated client.
```python
text=modal_input(
prompt,
firebase_client=st.session_state.firebase_client,
key="my_modal_input"
)
```
This will start a firestore listener thread watching for changes in a specific firestore document (collection='streamlit_modal_input',document=user.email).
Obviously your user should have the suitable permissions to read and write to this document in your firestore security rules.
A custom input widget is then rendered on the frontend, whose output is routed to this firestore document (via the firebase REST API).
The main python script will wait for the listener to receive the string before resuming execution, achieving a similar behavior as regular python `input` function.
Note that this is a one-shot input: After the initial string has been received, the result will be memorized in session_state and subsequent reruns will show a disabled widget returning the same string again.
## Example
```python
import streamlit as st
from streamlit_modal_input import modal_input
from firebase_user import FirebaseClient
if 'firebase_client' not in st.session_state:
with open("app_config.json",'r') as f:
config=json.load(f)
st.session_state.firebase_client=FirebaseClient(config)
st.session_state.firebase_client.auth.sign_in(user_email,user_password)
text=modal_input(
prompt,
firebase_client=st.session_state.firebase_client,
key="my_modal_input"
)
#The rest of the script will execute only when the input string has been received from the frontend
st.write(text)
#Now click the button below to trigger a rerun and see what happens : the widget gets disabled, but still returns the same string you entered at first pass.
st.button("Rerun")
```
Raw data
{
"_id": null,
"home_page": "https://github.com/B4PT0R/streamlit_modal_input",
"name": "streamlit-modal-input",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "",
"author": "Baptiste Ferrand",
"author_email": "bferrand.math@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/38/bf/01d1d87283ee49769b24c8854371c1fd13246ca6e114dd4f1d2f63dc3e8e/streamlit_modal_input-0.0.13.tar.gz",
"platform": null,
"description": "# streamlit-modal-input\n\nStreamlit component providing a 'modal' text input widget (actually pausing the script until a string is entered and returned). Implemented using the [firebase-user](https://github.com/B4PT0R/firebase_user) package to establish direct communication between the python backend and the React frontend. \n\nIt is meant first and foremost as a target widget for stdin redirection in case you wish to embed a live python interpreter in your streamlit app. \n\nRouting the interpreter's output to display widgets is fairly easy, but due to how Streamlit works, redirecting stdin to a widget in the app and achieving the expected blocking behavior was not that simple...\n\n## Installation instructions\n\n```sh\npip install streamlit-modal-input\n```\n\n## Usage instructions\n\nThis widget is meant to be used with the firebase-user package as follows.\n\nYou first declare a firebase user client with your firebase app json configuration file and authenticate your user:\n\n```python\nfrom firebase_user import FirebaseClient\n\nif 'firebase_client' not in st.session_state:\n with open(\"app_config.json\",'r') as f:\n config=json.load(f)\n st.session_state.firebase_client=FirebaseClient(config)\n st.session_state.firebase_client.auth.sign_in(user_email,user_password)\n\n```\nThen you can call the modal input widget, passing it the authenticated client.\n\n```python\ntext=modal_input(\n prompt,\n firebase_client=st.session_state.firebase_client,\n key=\"my_modal_input\"\n )\n```\n\nThis will start a firestore listener thread watching for changes in a specific firestore document (collection='streamlit_modal_input',document=user.email). \n\nObviously your user should have the suitable permissions to read and write to this document in your firestore security rules.\n\nA custom input widget is then rendered on the frontend, whose output is routed to this firestore document (via the firebase REST API).\n\nThe main python script will wait for the listener to receive the string before resuming execution, achieving a similar behavior as regular python `input` function.\n\nNote that this is a one-shot input: After the initial string has been received, the result will be memorized in session_state and subsequent reruns will show a disabled widget returning the same string again.\n\n## Example\n```python\nimport streamlit as st\nfrom streamlit_modal_input import modal_input\nfrom firebase_user import FirebaseClient\n\nif 'firebase_client' not in st.session_state:\n with open(\"app_config.json\",'r') as f:\n config=json.load(f)\n st.session_state.firebase_client=FirebaseClient(config)\n st.session_state.firebase_client.auth.sign_in(user_email,user_password)\n\n\ntext=modal_input(\n prompt,\n firebase_client=st.session_state.firebase_client,\n key=\"my_modal_input\"\n )\n\n#The rest of the script will execute only when the input string has been received from the frontend\n\nst.write(text)\n\n#Now click the button below to trigger a rerun and see what happens : the widget gets disabled, but still returns the same string you entered at first pass.\n\nst.button(\"Rerun\")\n\n\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Modal text input component for Streamlit",
"version": "0.0.13",
"project_urls": {
"Homepage": "https://github.com/B4PT0R/streamlit_modal_input"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "abc74bccea14a951d9aa0522f1e5f50a0c0cc72ea4b138ca77d42881945f2db6",
"md5": "7ad252846e74e2547c10ec3637d70743",
"sha256": "57da88c6faddc82d1fac5f82a4f4b4088f49fd13f253d578dd6be1056a2460fc"
},
"downloads": -1,
"filename": "streamlit_modal_input-0.0.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7ad252846e74e2547c10ec3637d70743",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 2962115,
"upload_time": "2024-02-02T21:16:58",
"upload_time_iso_8601": "2024-02-02T21:16:58.965026Z",
"url": "https://files.pythonhosted.org/packages/ab/c7/4bccea14a951d9aa0522f1e5f50a0c0cc72ea4b138ca77d42881945f2db6/streamlit_modal_input-0.0.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "38bf01d1d87283ee49769b24c8854371c1fd13246ca6e114dd4f1d2f63dc3e8e",
"md5": "873e78b1f1869f65ec310cc9f7135ade",
"sha256": "e5cdb976bcabe72739af17bf684162259508eefd46ecebb97584a603ee85568c"
},
"downloads": -1,
"filename": "streamlit_modal_input-0.0.13.tar.gz",
"has_sig": false,
"md5_digest": "873e78b1f1869f65ec310cc9f7135ade",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 523792,
"upload_time": "2024-02-02T21:17:02",
"upload_time_iso_8601": "2024-02-02T21:17:02.199839Z",
"url": "https://files.pythonhosted.org/packages/38/bf/01d1d87283ee49769b24c8854371c1fd13246ca6e114dd4f1d2f63dc3e8e/streamlit_modal_input-0.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-02 21:17:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "B4PT0R",
"github_project": "streamlit_modal_input",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "streamlit-modal-input"
}