Path: blob/main/examples/how_to/custom/react/slideshow.py
2012 views
import param12import panel as pn34from panel.custom import ReactComponent56pn.extension()78class JSSlideshow(ReactComponent):910index = param.Integer(default=0)1112_esm = """13export function render({ model }) {14const [index, setIndex] = model.useState("index")15const img = `https://picsum.photos/800/300?image=${index}`16return <img id="slideshow" src={img} onClick={ (event) => { setIndex(index+1) } }></img>17}18"""192021class PySlideshow(ReactComponent):2223index = param.Integer(default=0)2425_esm = """26export function render({ model }) {27const [index, setIndex] = model.useState("index")28const img = `https://picsum.photos/800/300?image=${index}`29return <img id="slideshow" src={img} onClick={ (event) => model.send_event('click', event) }></img>30}31"""3233def _handle_click(self, event):34self.index += 1353637pn.Row(38JSSlideshow(),39PySlideshow()40).servable()414243