streamlit-cytoscapejs

A Streamlit custom component for Cytoscape.js


Keywords
cytoscapejs, python, react, streamlit
License
MIT
Install
pip install streamlit-cytoscapejs==0.0.2

Documentation

Streamlit Cytoscape.js

Streamlit wrapper of React Cytoscape.js.

Installation

pip install streamlit-cytoscapejs

Try it

import streamlit as st
from streamlit_cytoscapejs import st_cytoscapejs

elements = [
    {"data": {"id": "one", "label": "Node 1"}, "position": {"x": 0, "y": 0}},
    {"data": {"id": "two", "label": "Node 2"}, "position": {"x": 100, "y": 0}},
    {"data": {"source": "one", "target": "two", "label": "Edge from Node1 to Node2"}},
]
stylesheet = [
    {"selector": "node", "style": {"width": 20, "height": 20, "shape": "rectangle"}},
    {"selector": "edge", "style": {"width": 10}},
]

st.title("Hello Cytoscape.js")
st_cytoscapejs(elements, stylesheet)

Development

Install

  • JS side
cd streamlit_cytoscape/frontend
npm install
  • Python side
conda create -n streamlit-cytoscapejs python=3.7
conda activate streamlit-cytoscapejs
pip install -e .

Run

Both webpack dev server and Streamlit should run at the same time.

  • JS side
cd streamlit_cytoscape/frontend
npm run start
  • Python side
streamlit run app.py

Next steps

I don't plan to make a lot of progress on this for now (except if huge interest) but if you want to contribute/take over its development I'm happy to lend a hand :).

Obviously missing lots of things like:

  • viewport manipulation props from React cytoscapejs.
  • custom layout
  • adding an extension (but also you'd better fork this repo and add the extension yourself I think :/)

References