Skip to main content

Embed the power of Processing.org in your Streamlit app

Project description

streamlit_p5

Embed your processing sketches in Streamlit!

Installation instructions

pip install streamlit streamlit_p5

Quickstart

streamlit run example.py

Usage instructions

The sketch object takes a few arguments:

  • sketch : a string representing your P5js sketch
  • width : width of the element in Streamlit
  • height : height of the element in Streamlit (make sure to match these with your sketch!)
  • data : a Python dict to pass to the p5 sketch

Example:

Basic

import streamlit as st
from streamlit_p5 import sketch

p5_sketch = sketch("""
function setup() {
   createCanvas(700, 500);
}

// The background function is a statement that tells the computer
// which color (or gray value) to make the background of the display window 
function draw() {
   background(204, 153, 0);
}
""", width=700, height=500)

Advanced

import streamlit as st
from streamlit_p5 import sketch

value = sketch("""
let word=""
function setup() { 
  createCanvas(700, 500);
  noStroke();
  word=dataToPass.name. // get value passed from Streamlit
}

function draw() {
  background(204, 120);
  fill(0)
  textFont('Courier New')
  textSize(50)
  text(word, mouseX, mouseY)
}

function mousePressed() {
  sendDataToPython({  //Send data to Streamlit - causes a re-render
          value: {
            mouseX: mouseX,
            mouseY: mouseY
          },
          dataType: "json",
        })
}
""", data={
  "name" : "Bob the Builder"
}, width=700, height=500)

Wanna build this from source? just run:

python setup.py sdist bdist_wheel && twine upload dist/*
twine upload dist/*

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_p5-0.0.3.tar.gz (248.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_p5-0.0.3-py3-none-any.whl (497.2 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_p5-0.0.3.tar.gz.

File metadata

  • Download URL: streamlit_p5-0.0.3.tar.gz
  • Upload date:
  • Size: 248.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for streamlit_p5-0.0.3.tar.gz
Algorithm Hash digest
SHA256 109dd35b88d9a2de6c4192b7d47ed56620ec83a474929b1c27136879beb14673
MD5 2d58cb4774ed8ef6ac0f702939eee2b4
BLAKE2b-256 42de4a3e3316e4cc1fad499a787f9db561a70182f9d80aa623d92ade46a90b2c

See more details on using hashes here.

File details

Details for the file streamlit_p5-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: streamlit_p5-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 497.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for streamlit_p5-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 15f38ada0ba09e1781fafb2111b068a95d0c5a0bee45d881eac2a73b7b69fae5
MD5 4ce4e8d82459da519455982fafd9b80d
BLAKE2b-256 09eaf8c3ff8aa80c01ac1333f3f8ff435519c9c6aee61f08c9ece1bf31433fab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page