import panel as pn
import param
import textwrap
class MyApp(pn.viewable.Viewer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def log_count(self, clicks):
pn.state.log(f"Button clicked {clicks} times", level="error")
def button(self):
click_me = pn.widgets.Button(name="Push button!", button_type="primary")
pn.bind(self.log_count, click_me.param.clicks, watch=True)
return click_me
def message(self):
return pn.pane.Markdown(textwrap.dedent(
"""
# Logging example
When you push the button, an error message will be logged.
Click the button a few times, then
[check the admin panel](/admin) - look for app = `panel.state`
If the admin panel is broken, make sure you started
this file with `panel serve --admin` option.
"""
))
def __panel__(self):
return pn.Column(self.message, self.button)
MyApp().servable()
Just copy the source above to a file (let’s say “app.py”, then run panel serve --admin app.py