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.
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for streamlit_js_eval-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86f092497d1254fd5820bcc3e389a35e9dc638684398a8fa945d0d0b9034fa4a |
|
MD5 | b56fb6d6b9ebd72557e96e09c7ea4ec4 |
|
BLAKE2b-256 | 4a820c20e8b3faa8f1d9ac95cefd6e9a8302b7e854c1ebc50a80c9491e44aeb8 |