Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/examples/how_to/custom/react/slideshow.py
2012 views
1
import param
2
3
import panel as pn
4
5
from panel.custom import ReactComponent
6
7
pn.extension()
8
9
class JSSlideshow(ReactComponent):
10
11
index = param.Integer(default=0)
12
13
_esm = """
14
export function render({ model }) {
15
const [index, setIndex] = model.useState("index")
16
const img = `https://picsum.photos/800/300?image=${index}`
17
return <img id="slideshow" src={img} onClick={ (event) => { setIndex(index+1) } }></img>
18
}
19
"""
20
21
22
class PySlideshow(ReactComponent):
23
24
index = param.Integer(default=0)
25
26
_esm = """
27
export function render({ model }) {
28
const [index, setIndex] = model.useState("index")
29
const img = `https://picsum.photos/800/300?image=${index}`
30
return <img id="slideshow" src={img} onClick={ (event) => model.send_event('click', event) }></img>
31
}
32
"""
33
34
def _handle_click(self, event):
35
self.index += 1
36
37
38
pn.Row(
39
JSSlideshow(),
40
PySlideshow()
41
).servable()
42
43