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.
Introduction
These two components offer more flexibility in creating Streamlit applications by allowing you to easily incorporate HTML and JS.
Here are some examples:
-
import streamlit as st from st_bridge import bridge, html data = bridge("my-bridge", default="no button is clicked") html(""" <button onClick="stBridges.send('my-bridge', 'button 1 is clicked')">Button 1</button> <button onClick="stBridges.send('my-bridge', 'button 2 is clicked')">Button 2</button> <button onClick="stBridges.send('my-bridge', 'button 3 is clicked')">Button 3</button> """) st.write(data)
Installation
pip install streamlit-bridge
API
Bridge Component
def bridge(
name: str,
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
default: the initial return value of the component before the user has interacted with it.
key: streamlit component's id
"""
To send data from the client to a corresponding bridge component with <bridge-name>
, use the function: window.stBridges.send(<bridge-name>, <data>);
or window.parent.stBridges.send(<bridge-name>, <data>);
if you are running it inside an component (i.e., running inside an iframe).
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
"""
pass
Development
- To build a streamlit component after modifying them:
- visiting their folder:
st_bridge/<component>
- run
yarn install; yarn build
- visiting their folder:
- To test a component interactively, set
_RELEASE = False
inst_bridge/<component>.py
and runstreamlit run st_bridge/<component>.py
- To release, build the streamlit components first, then run
poetry publish --build
.
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
Built Distribution
File details
Details for the file streamlit_bridge-1.1.3.tar.gz
.
File metadata
- Download URL: streamlit_bridge-1.1.3.tar.gz
- Upload date:
- Size: 2.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.13 Linux/3.10.0-1160.76.1.el7.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95aa1bedbb6779c270675764b524e19088ba511d17ec2bd87272c3dfa52f3d88 |
|
MD5 | 7d599e14a0ae55035f3d26a32ca5beb5 |
|
BLAKE2b-256 | 15d8626346de4b2dd54e135e6db0d938995ef75348ed316315fdc71ced267b0b |
File details
Details for the file streamlit_bridge-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: streamlit_bridge-1.1.3-py3-none-any.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.13 Linux/3.10.0-1160.76.1.el7.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3d463545f4a8f90625a337f5d7d47ece7f840123cb41f04dbaef152e16fe732 |
|
MD5 | 348b0670b44de65e1f2a25146b36f251 |
|
BLAKE2b-256 | 241cc2ad5daf9d9ed5f7a2b04f6d200b379ebda8034f32a82d88ce7070507fa4 |