# Streamlit-JS-Eval
[](https://badge.fury.io/py/streamlit_js_eval) [](https://static.pepy.tech/badge/streamlit-js-eval)
[]([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.
## 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 calling SJE from inside a branch in Streamlit code does not work (e.g. in a loop, `if-else` block, ...)
Raw data
{
"_id": null,
"home_page": "https://github.com/aghasemi/streamlit_js_eval",
"name": "streamlit-js-eval",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Python,Streamlit,JavaScript",
"author": "Alireza Ghasemi",
"author_email": "ghasemi.a.ir@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/76/e4/bde7a73ed1967e0713e4e361c9b1a3ee87e66399c39422be13498467dd72/streamlit_js_eval-0.1.7.tar.gz",
"platform": null,
"description": "# Streamlit-JS-Eval\n\n[](https://badge.fury.io/py/streamlit_js_eval) [](https://static.pepy.tech/badge/streamlit-js-eval)\n[]([https://share.streamlit.io/streamlit/corp/main](https://aghasemi-streamlit-js-eval-example-yleu91.streamlitapp.com/))\n\n\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. \n\n## Install\n\n```python\npip3 install streamlit_js_eval\n```\n\n## Example\n\n```python\nst.write(f\"Screen width is {streamlit_js_eval(js_expressions='screen.width', key = 'SCR')}\")\n```\n`key` is an arbitrary but unique string, required by Streamlit components API for each call to `streamlit_js_eval`.\n\n### Common JavaScript functionalities\n\nSome more common functionalities are already implemented as Python functions. Examples include:\n\n```python\n# Returns user's location after asking for permission when the user clicks the generated link with the given text\nlocation = get_geolocation()\n# The URL parts of the page\nlocation_json = get_page_location()\n```\n\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/).\n\n## Known Limitations\n\n- It seems calling SJE from inside a branch in Streamlit code does not work (e.g. in a loop, `if-else` block, ...)\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A custom Streamlit component to evaluate arbitrary Javascript expressions.",
"version": "0.1.7",
"project_urls": {
"Homepage": "https://github.com/aghasemi/streamlit_js_eval"
},
"split_keywords": [
"python",
"streamlit",
"javascript"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9815e8abb57a25eb11ee5e645ef123ee7c38f5fecbbea5268e92674f1b65ba61",
"md5": "e4ae9c31c86a5c95f23180b3b61e1e55",
"sha256": "c99c23d1c6e2a27fd45794262e2ac07befaef9603a86e4e325a9e980cad8c78d"
},
"downloads": -1,
"filename": "streamlit_js_eval-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e4ae9c31c86a5c95f23180b3b61e1e55",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7912,
"upload_time": "2024-03-06T11:37:15",
"upload_time_iso_8601": "2024-03-06T11:37:15.248921Z",
"url": "https://files.pythonhosted.org/packages/98/15/e8abb57a25eb11ee5e645ef123ee7c38f5fecbbea5268e92674f1b65ba61/streamlit_js_eval-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "76e4bde7a73ed1967e0713e4e361c9b1a3ee87e66399c39422be13498467dd72",
"md5": "321e8bcf42c21bb19e8bef0cf9df2083",
"sha256": "af80eff45e2f23a676588578aff7d2790080360528c656f4a4476c1484574c97"
},
"downloads": -1,
"filename": "streamlit_js_eval-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "321e8bcf42c21bb19e8bef0cf9df2083",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7049,
"upload_time": "2024-03-06T11:37:16",
"upload_time_iso_8601": "2024-03-06T11:37:16.135260Z",
"url": "https://files.pythonhosted.org/packages/76/e4/bde7a73ed1967e0713e4e361c9b1a3ee87e66399c39422be13498467dd72/streamlit_js_eval-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-06 11:37:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aghasemi",
"github_project": "streamlit_js_eval",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "streamlit-js-eval"
}