Skip to main content

A hidden streamlit component that allows client side (javascript) to trigger events on the server side (python) and vice versa

Project description

Streamlit Bridge

Two Streamlit components that allow client side (javascript) to send data to the server side (python) and render HTML content without being processed by Markdown.

License

Introduction

These two components offer more flexibility in creating Streamlit applications by allowing you to easily incorporate HTML and JS.

Here are some examples:

  1. List of inline buttons Streamlit inline buttons

    import streamlit as st
    from st_bridge import bridge, html
    
    data = bridge("my-bridge", default="no button is clicked")
    
    html("""
    <button onClick="stBridges.sendText('my-bridge', 'button 1 is clicked')">Button 1</button>
    <button onClick="stBridges.sendText('my-bridge', 'button 2 is clicked')">Button 2</button>
    <button onClick="stBridges.sendText('my-bridge', 'button 3 is clicked')">Button 3</button>
    """)
    
    st.write(data)
    

Installation

pip install streamlit-bridge

API

Bridge Component

def bridge(
    name: str,
    json: bool = False,
    default: Optional[Any] = None,
    key: Optional[str] = None,
):
    """Create a new instance of "Streamlit Bridge", allowing call from the client to
    the server.

    Everytime JS client send data to the server, streamlit will trigger a rerun and the data
    is returned by this function.

    Args:
        name: unique name of the bridge to identify the bridge Javascript's call will send data to
        json: whether to parse the data as JSON
        default: the initial return value of the component before the user has interacted with it.
        key: streamlit component's id
    ."""
    pass

HTML Component

def html(html: str, iframe: bool = False, key: Optional[str]=None) -> None:
    """Render HTML in Streamlit without being processed by Markdown.

    Args:
        html: HTML to render
        iframe: whether to render the HTML in an iframe or in the main document.
                By default streamlit component is rendered inside an iframe, so by
                setting it to false, we allow the HTML to rendered in the main document.
        key: streamlit component's id
    """

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-bridge-1.0.2.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

streamlit_bridge-1.0.2-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file streamlit-bridge-1.0.2.tar.gz.

File metadata

  • Download URL: streamlit-bridge-1.0.2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.4.0

File hashes

Hashes for streamlit-bridge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 bcb252f2ae4bd4c77f871bcca42ecbcd7c5214d3406d192416e276ce09b12e9c
MD5 12c9d7933ba89b23caf0a1fa572700d7
BLAKE2b-256 c00a1c4e6296e5f44e5eadb2aa06f88e158063bcb703e04469c46b2057375fd5

See more details on using hashes here.

File details

Details for the file streamlit_bridge-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_bridge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a5b4a919dcc5978e67e93b2e8894e0152217d21ee9e8375069c1f096a0cd44e
MD5 e3371395f94e028ef34a1e02020f1355
BLAKE2b-256 9775c55e8cf3e95c0f2a0e3cfc62ddeafd964eb0d17bc769f2d31974b6f56646

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