Spaces:
Sleeping
Sleeping
kolibril13
commited on
Commit
•
f68bbbc
1
Parent(s):
1dbcc8d
add ipyreact and widget
Browse files- pages/sine_widget.py +63 -0
- requirements.txt +1 -0
pages/sine_widget.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ipyreact
|
2 |
+
from traitlets import List, Any
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
class TldrawSineWidget(ipyreact.ReactWidget):
|
6 |
+
points = List(List(Any())).tag(sync=True)
|
7 |
+
_esm = """
|
8 |
+
import { TDShapeType, Tldraw } from "@tldraw/tldraw";
|
9 |
+
import * as React from "react";
|
10 |
+
|
11 |
+
export default function App({ points }) {
|
12 |
+
|
13 |
+
const [app, setApp] = React.useState()
|
14 |
+
|
15 |
+
const handleMount = React.useCallback((app: Tldraw) => {
|
16 |
+
setApp(app)
|
17 |
+
}, []);
|
18 |
+
|
19 |
+
React.useEffect(() => {
|
20 |
+
if (app) {
|
21 |
+
app.createShapes({
|
22 |
+
type: "draw",
|
23 |
+
id: "draw1",
|
24 |
+
color: 'red',
|
25 |
+
points: points,
|
26 |
+
});
|
27 |
+
}
|
28 |
+
}, [points, app])
|
29 |
+
|
30 |
+
return (
|
31 |
+
<div
|
32 |
+
style={{
|
33 |
+
position: "relative",
|
34 |
+
width: "800px",
|
35 |
+
height: "350px",
|
36 |
+
}}
|
37 |
+
>
|
38 |
+
<Tldraw onMount={handleMount} onChange={e => console.log("hii")} />
|
39 |
+
</div>
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
"""
|
44 |
+
|
45 |
+
import solara
|
46 |
+
import numpy as np
|
47 |
+
|
48 |
+
float_value = solara.reactive(0)
|
49 |
+
|
50 |
+
@solara.component
|
51 |
+
def Page():
|
52 |
+
stretchx = 50
|
53 |
+
x = np.arange(0,4*np.pi*stretchx , 2)
|
54 |
+
y = 130*np.sin(x*1/stretchx+float_value.value)+150
|
55 |
+
|
56 |
+
points = np.column_stack((x, y)).tolist()
|
57 |
+
TldrawSineWidget.element(points=points)
|
58 |
+
solara.Markdown(f"**Float value**: {float_value.value}")
|
59 |
+
solara.FloatSlider("Some float", value=float_value, min=0, max=4*np.pi, step=0.1)
|
60 |
+
|
61 |
+
with solara.Row():
|
62 |
+
solara.Button("Reset", on_click=lambda: float_value.set(0))
|
63 |
+
Page()
|
requirements.txt
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
geemap>=0.21.0
|
2 |
leafmap
|
3 |
mapwidget
|
|
|
4 |
solara
|
5 |
geopandas
|
|
|
1 |
geemap>=0.21.0
|
2 |
leafmap
|
3 |
mapwidget
|
4 |
+
ipyreact
|
5 |
solara
|
6 |
geopandas
|