I'd like to make a dashboard with pyviz/panel
so that it doesn't refresh live as soon as the values of the widgets are changed. Instead, I'd like for it to wait for a button click and only then, change the values in the dashboard accordingly.
A minimal working example is as follow. Here I'd like to generate some random numbers every time the button is clicked, but it doesn't seem to do anything.
In my real-world task, I would hit the database to get a few rows of data, based on the input widgets. I imagine that it could work the same way?
import numpy as np
import pandas as pd
import param
import panel as pn
pn.extension()
class UserDash(param.Parameterized):
mean = pn.widgets.IntSlider(value=10, start=0, end=100)
output_pane = pn.widgets.TextInput(value='Ready')
button = pn.widgets.Button(name='Generate', button_type='primary')
button.on_click(output_pane)
@param.depends('button')
def output_pane(self):
print(self.mean.value)
df = pd.DataFrame({'x': np.random.normal(int(self.mean.value), 1, 5)}, index=range(5))
return df
def panel(self):
return pn.Column(self.mean, self.button, self.output_pane)
dash = UserDash()
dash.panel().servable()
I am using panel 0.6.0, running on Jupyter 6.0.0. Thanks!