Py.Cafe

kolibril13/

minimal-p5

Coffee Beans Dashboard using Solara

DocsPricing
  • app.py
  • requirements.txt
  • widget.js
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import anywidget
from pathlib import Path
import traitlets

class HelloWidget(anywidget.AnyWidget):
    _esm = """
    import p5 from "https://esm.sh/p5";

    function render({ model, el }) {
        new p5((p) => {
            p.setup = () => {
                p.createCanvas(600, 400, p.WEBGL);
            };

            p.draw = () => {
                p.background(200);
                p.translate(0, 0, 0);
                p.fill(255, 165, 0);
                p.sphere(model.get("radius")); 
            };
        }, el);
    }
    export default { render };
    """
    radius = traitlets.Any().tag(sync=True)

viewer = HelloWidget()

viewer.radius = 100
page = viewer
widget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import p5 from "https://esm.sh/p5";

function render({ model, el }) {
    new p5((p) => {
        p.setup = () => {
            p.createCanvas(600, 400, p.WEBGL);
        };

        p.draw = () => {
            p.background(200);
            p.translate(0, 0, 0);
            p.fill(255, 165, 0);
            p.sphere(model.get("radius")); 
        };
    }, el);
}

export default { render };