Skip to content

Instantly share code, notes, and snippets.

@maartenbreddels
Created December 13, 2022 19:58
Show Gist options
  • Save maartenbreddels/06a4dd6a9b8588ae0233a640cd88d647 to your computer and use it in GitHub Desktop.
Save maartenbreddels/06a4dd6a9b8588ae0233a640cd88d647 to your computer and use it in GitHub Desktop.
Reacton running in Panel
# $ panel serve reacton-in-panel.py
import panel as pn
import reacton
import reacton.ipywidgets as w
@reacton.component
def ButtonClick(label="Hi"):
clicks, set_clicks = reacton.use_state(0)
def increment():
set_clicks(clicks + 1)
return w.Button(description=f"{label}: Clicked {clicks} times", on_click=increment)
# this creates just an element, Panel doesn't know what to do with that
element = ButtonClick(label="Ola")
# we explicitly ask Reacton to render it, and give us the widget
button_widget, render_context = reacton.render_fixed(element)
# mark this panel to be served by the panel server
pn.panel(button_widget).servable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment