streamlit-js-eval is a custom Streamlit component that enables developers to execute arbitrary JavaScript expressions directly within a Streamlit application. It facilitates interactions with the browser DOM, local storage, window properties, and more, returning results back to Python. The current version is 1.0.0, and it follows an infrequent release cadence, with stability being a primary focus.
pip install streamlit-js-evalVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `streamlit_js_eval` to interact with browser-side JavaScript, including retrieving the current URL, setting and getting local storage values, getting screen dimensions, and performing a page redirect. Each `streamlit_js_eval` call requires a unique `key`.
Ensure a unique `key` is used for each distinct evaluation call. If results aren't updating as expected, consider triggering a Streamlit rerun or ensuring the JS expression itself produces a new value. For fire-and-forget actions that don't require a return value, set `want_result=False`.
Sanitize or strictly validate any `js_expressions` derived from user input. Limit the scope of executable JavaScript to only what is absolutely necessary and safe.
Always provide a unique `key` string (e.g., `key="my_unique_eval_1"`) to every `streamlit_js_eval` call in your application.
Ensure the library is installed by running `pip install streamlit-js-eval`. Verify your import statement is `from streamlit_js_eval import streamlit_js_eval`.
Ensure each `streamlit_js_eval` call has a unique `key`. If you expect a result, make sure `want_result` is not set to `False`. For fire-and-forget operations, setting `want_result=False` is efficient. If you need re-evaluation on every run, consider using a dynamic `key` or updating `js_expressions` to force a change.
Assign a unique `key` string to every instance of `streamlit_js_eval` in your application (e.g., `key='eval_id_1'`, `key='eval_id_2'`).