A custom Streamlit component to evaluate arbitrary Javascript expressions.
Project description
Streamlit-JS-Eval
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 for more information about Web APIs.
- Version 0.1.7 - March 2024: Proposed a workaround for issue #2.
Install
pip3 install streamlit_js_eval
Example
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:
# 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.
Known Limitations
- It seems SJE has issues with
st.buttonwhen getting called from inside a branch in Streamlit (e.g. in a loop,if-elseblock, ...). In version 0.1.7, you may use the custombootstrapButtonas a workaround in such situations.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_js_eval_no_logs-0.1.8-py3-none-any.whl.
File metadata
- Download URL: streamlit_js_eval_no_logs-0.1.8-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f737bfcd305462c009112384db112bd908350c8ee5ef8ae7a6b003f18f66aef
|
|
| MD5 |
b1e8ffb2f62870f936e01d48c6ad3e53
|
|
| BLAKE2b-256 |
88949858754a389a562ff240b9cb2167a3eed469c1b3687805962a42d963b11f
|