Skip to main content

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.

Metadata

Release files for streamlit-message-passing 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-message-passing 0.1.1
File Size Uploaded
streamlit_message_passing-0.1.1.tar.gz 439.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-message-passing 0.1.1
File Interpreter ABI Platform
streamlit_message_passing-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 883.3 kB

Release files / streamlit_message_passing-0.1.1.tar.gz

Download URL streamlit_message_passing-0.1.1.tar.gz
Size 439.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0a2ab5b7d75ec1ad5a986a9eb6799235dfbcbe131d5bf20a8325e2bcd3b3c721
BLAKE2b-256 checksum
How to use checksums
44e02c6e82399153c7a288892444106671b18a1b254e2cc296480da85d9c3a4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.9.6 Darwin/22.6.0

Release files / streamlit_message_passing-0.1.1-py3-none-any.whl

Download URL streamlit_message_passing-0.1.1-py3-none-any.whl
Size 443.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f582a28884dbd3863196f5a1020b78042438e9a77d347f875d477f80734664f4
BLAKE2b-256 checksum
How to use checksums
0164d0452abb4d53e79cd801d81068795c31f11495be0d9faf75b76cf3d3205b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.9.6 Darwin/22.6.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page