Created
December 13, 2022 19:58
-
-
Save maartenbreddels/06a4dd6a9b8588ae0233a640cd88d647 to your computer and use it in GitHub Desktop.
Reacton running in Panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ 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