streamlit-js-callback
Eval js code with callbaack.
Installation instructions
pip install streamlit-js-callback
Usage instructions
import random
import streamlit as st
from streamlit_js_callback import streamlit_js_callback
print("Start render..")
st.subheader("JS Callback Component")
def use_return():
result1 = streamlit_js_callback("""
console.log("eval 1 + 1")
return 1 + 1
""")
if result1:
st.text("Received by use_return: " + str(result1))
def use_send_message():
result2 = streamlit_js_callback("""
console.log("hello")
sendMessage("hello")
""")
if result2:
st.text("Received by use_send_message: " + str(result2))
def exec_async():
res = streamlit_js_callback("""
return await fetch("https://reqres.in/api/products/3").then(function(response) {
return response.json();
})
""")
if res:
st.text("Received by exec_async: " + str(res))
def exec_event_listen():
if st.button("btn1"):
print("btn1 click")
result3 = streamlit_js_callback("""
console.log("init 3..")
let clickCount = 0
window.parent.document.querySelectorAll('button[kind="secondary"]').forEach((item) => {
item.addEventListener("click", function(e) {
clickCount += 1
console.log(clickCount)
sendMessage(clickCount)
});
})
""")
if result3:
st.text(f"Received event: {result3}")
print(f"Received event: {result3}")
use_return()
use_send_message()
exec_async()
exec_event_listen()
# my_key = "my_key"
#
#
# @st.fragment
# def exec_in_context_2():
# global my_key
# print("my_key", my_key)
# result4 = streamlit_js_callback("""
# const res = String(new Date())
# console.log(res)
# return res
# """, key=my_key)
# if result4:
# st.text("Received by exec_in_context: " + str(result4))
# print(f"Received by exec_in_context: {result4}")
# my_key = str(random.randint(0, 99999))
# print("my_key", my_key)
#
#
# @st.fragment
# def exec_in_context():
# if st.button("btn2"):
# print("btn2 click")
# exec_in_context_2()
# print('exec_in_context finish.')
#
#
# exec_in_context()
print("Finish render")
Metadata
Release files for streamlit-js-callback 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit-js-callback-1.0.2.tar.gz | 403.5 kB | Without provenance | Details for streamlit-js-callback-1.0.2.tar.gz |
Release files / streamlit-js-callback-1.0.2.tar.gz
| Download URL | streamlit-js-callback-1.0.2.tar.gz |
|---|---|
| Size | 403.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5097fdb157e9dba835f140393fd494c28bf1c1ed0794b8ba2191cb9aae1be20b
|
|
BLAKE2b-256 checksum How to use checksums |
79aa9cfb9178dd464775179dbbba4152ab2700bbf5d5e079da33bfc2e7cfc986
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Security for streamlit-js-callback 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.