Skip to main content

A custom Streamlit component to evaluate arbitrary Javascript expressions.

Project description

Streamlit-JS-Eval

PyPI version Downloads Streamlit App

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.

Known Limitations

  • It seems calling SJE from inside a branch in Streamlit code does not work (e.g. in a loop, if-else block, ...)

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

streamlit_js_eval-0.1.7.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

streamlit_js_eval-0.1.7-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_js_eval-0.1.7.tar.gz.

File metadata

  • Download URL: streamlit_js_eval-0.1.7.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for streamlit_js_eval-0.1.7.tar.gz
Algorithm Hash digest
SHA256 af80eff45e2f23a676588578aff7d2790080360528c656f4a4476c1484574c97
MD5 321e8bcf42c21bb19e8bef0cf9df2083
BLAKE2b-256 76e4bde7a73ed1967e0713e4e361c9b1a3ee87e66399c39422be13498467dd72

See more details on using hashes here.

File details

Details for the file streamlit_js_eval-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_js_eval-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c99c23d1c6e2a27fd45794262e2ac07befaef9603a86e4e325a9e980cad8c78d
MD5 e4ae9c31c86a5c95f23180b3b61e1e55
BLAKE2b-256 9815e8abb57a25eb11ee5e645ef123ee7c38f5fecbbea5268e92674f1b65ba61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page