Streamlit component for doing message passing between parent window and server via JS
Project description
streamlit-message-passing
Streamlit component for doing message passing between parent window and server via JS
Installation instructions
pip install streamlit-message-passing
Usage instructions
import streamlit as st
from msgpassing import listen_for_parameters
# If parent window is running on http://localhost:8080 ...
data = listen_for_parameters(web_url="http://localhost:8080")
# We can wait until we have these parameters:
if not data:
st.stop()
st.markdown("Parameters is: ```%s```" % json.dumps(data, indent=2))
On the parent window, you can do something like this:
<iframe src="http://localhost:8501/" frameborder="0"></iframe>
<script>
document.addEventListener('DOMContentLoaded', function () {
const messageHandler = (event) => {
console.debug("Received message from iframe:", event.data, event.origin)
// Optional: Check if we're receiving messages from our dashboard only
// We assume that the streamlit app is running on http://localhost:8501
if (event.origin !== "http://localhost:8501") return;
if (event.data.type === "ready") {
// We are ready to send these parameters to streamlit
const msg = {
type: "parameters",
foo: "1",
bar: 2
};
console.debug("Sending parameters to iframe:", msg);
event.source.postMessage(msg, "http://localhost:8501");
}
};
window.addEventListener("message", messageHandler, false);
});
</script>
See iframe.html
for a full example.
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 Distribution
Built Distribution
Close
Hashes for streamlit_message_passing-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35eeb5fbe1e19ffe698dad4f9e2a66708426e666a408a739a10fc4e0f6161688 |
|
MD5 | 2dd2b22c51d7819ac5b5751ce229caf2 |
|
BLAKE2b-256 | ca089f8d1fba662e4a187cc23555cf93012f043250814f85a0c9b9c6409f6d91 |
Close
Hashes for streamlit_message_passing-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7243850334cfdd32b530afff7be4c3729a0f24745fbc66ca2a5dc4a2f0f52ea2 |
|
MD5 | f2028db03d5482fe5c2a79418d0bb996 |
|
BLAKE2b-256 | 679ad8c2e98827c4c5ccd994b0fceb5702ab9f7ca4031e96f6a511a1aec5cca2 |