# Streamlit-JS-Eval
[![PyPI version](https://badge.fury.io/py/streamlit_js_eval.svg?service=github)](https://badge.fury.io/py/streamlit_js_eval) [![Downloads](https://static.pepy.tech/badge/streamlit-js-eval?service=github)](https://static.pepy.tech/badge/streamlit-js-eval)
[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)]([https://share.streamlit.io/streamlit/corp/main](https://aghasemi-streamlit-js-eval-example-yleu91.streamlitapp.com/))
SJE is a custom Streamlit component, built to evaluate arbitrary Javascript expressions and return the result. It can become useful in doing certain functionalities which are _simple_ things in JavaScript, but unavailable or difficult to do in Streamlit. Examples include cookie management, writing to clipboard, getting device width (e.g. to check if we are on a mobile device), getting browser language, sharing something through Android's share feature, knowing user agent, etc. See [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API) for more information about Web APIs.
- _Version 0.1.7 - March 2024_: Proposed a workaround for issue #2.
## Install
```python
pip3 install streamlit_js_eval
```
## Example
```python
st.write(f"Screen width is {streamlit_js_eval(js_expressions='screen.width', key = 'SCR')}")
```
`key` is an arbitrary but unique string, required by Streamlit components API for each call to `streamlit_js_eval`.
### Common JavaScript functionalities
Some more common functionalities are already implemented as Python functions. Examples include:
```python
# Returns user's location after asking for permission when the user clicks the generated link with the given text
location = get_geolocation()
# The URL parts of the page
location_json = get_page_location()
```
See `streamlit_js_eval/__init__.py` for more functions. Check a demo in `example.py` or [see it live](https://aghasemi-streamlit-js-eval-example-yleu91.streamlitapp.com/).
## Known Limitations
- It seems SJE has issues with `st.button` when getting called from inside a branch in Streamlit (e.g. in a loop, `if-else` block, ...). In version 0.1.7, you may use the custom `bootstrapButton` as a workaround in such situations.
Raw data
{
"_id": null,
"home_page": "https://github.com/aghasemi/streamlit_js_eval_no_log",
"name": "streamlit-js-eval-no-logs",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "Python, Streamlit, JavaScript",
"author": "['Alireza Ghasemi', 'Fabian Lucas']",
"author_email": "['ghasemi.a.ir@gmail.com', 'fl@msr.de']",
"download_url": null,
"platform": null,
"description": "# Streamlit-JS-Eval\r\n\r\n[![PyPI version](https://badge.fury.io/py/streamlit_js_eval.svg?service=github)](https://badge.fury.io/py/streamlit_js_eval) [![Downloads](https://static.pepy.tech/badge/streamlit-js-eval?service=github)](https://static.pepy.tech/badge/streamlit-js-eval)\r\n[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)]([https://share.streamlit.io/streamlit/corp/main](https://aghasemi-streamlit-js-eval-example-yleu91.streamlitapp.com/))\r\n\r\n\r\nSJE is a custom Streamlit component, built to evaluate arbitrary Javascript expressions and return the result. It can become useful in doing certain functionalities which are _simple_ things in JavaScript, but unavailable or difficult to do in Streamlit. Examples include cookie management, writing to clipboard, getting device width (e.g. to check if we are on a mobile device), getting browser language, sharing something through Android's share feature, knowing user agent, etc. See [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API) for more information about Web APIs. \r\n\r\n- _Version 0.1.7 - March 2024_: Proposed a workaround for issue #2.\r\n\r\n\r\n## Install\r\n\r\n```python\r\npip3 install streamlit_js_eval\r\n```\r\n\r\n## Example\r\n\r\n```python\r\nst.write(f\"Screen width is {streamlit_js_eval(js_expressions='screen.width', key = 'SCR')}\")\r\n```\r\n`key` is an arbitrary but unique string, required by Streamlit components API for each call to `streamlit_js_eval`.\r\n\r\n### Common JavaScript functionalities\r\n\r\nSome more common functionalities are already implemented as Python functions. Examples include:\r\n\r\n```python\r\n# Returns user's location after asking for permission when the user clicks the generated link with the given text\r\nlocation = get_geolocation()\r\n# The URL parts of the page\r\nlocation_json = get_page_location()\r\n```\r\n\r\nSee `streamlit_js_eval/__init__.py` for more functions. Check a demo in `example.py` or [see it live](https://aghasemi-streamlit-js-eval-example-yleu91.streamlitapp.com/).\r\n\r\n## Known Limitations\r\n\r\n- It seems SJE has issues with `st.button` when getting called from inside a branch in Streamlit (e.g. in a loop, `if-else` block, ...). In version 0.1.7, you may use the custom `bootstrapButton` as a workaround in such situations.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A custom Streamlit component to evaluate arbitrary Javascript expressions.",
"version": "0.1.8",
"project_urls": {
"Homepage": "https://github.com/aghasemi/streamlit_js_eval_no_log"
},
"split_keywords": [
"python",
" streamlit",
" javascript"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "88949858754a389a562ff240b9cb2167a3eed469c1b3687805962a42d963b11f",
"md5": "b1e8ffb2f62870f936e01d48c6ad3e53",
"sha256": "7f737bfcd305462c009112384db112bd908350c8ee5ef8ae7a6b003f18f66aef"
},
"downloads": -1,
"filename": "streamlit_js_eval_no_logs-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b1e8ffb2f62870f936e01d48c6ad3e53",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8681,
"upload_time": "2024-08-07T14:43:41",
"upload_time_iso_8601": "2024-08-07T14:43:41.126972Z",
"url": "https://files.pythonhosted.org/packages/88/94/9858754a389a562ff240b9cb2167a3eed469c1b3687805962a42d963b11f/streamlit_js_eval_no_logs-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-07 14:43:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aghasemi",
"github_project": "streamlit_js_eval_no_log",
"github_not_found": true,
"lcname": "streamlit-js-eval-no-logs"
}