I am using a button to trigger a function. For this, I am using on_click(my_function)
.
While my_function
may update some widgets, it should also modify a variable that is later accessed by another function. This variable is not stored in any widget.
Edit: After some more reading through the questions on Discourse, I think the better formulation of this question would be:
I have data which should be transformed by the user through a GUI. The data could be stored in a pd.DataFrame
, or another data type. If different parts of my Panel GUI perform different transformations on the data - MUST I store the data in a class and have all transformation functions as class methods?
Is there a more elegant way of doing this? I am currently using global
variables:
# %%
import panel as pn
pn.extension()
my_list = []
def create_list(event):
global my_list
my_list = [1, 2, 3, 4, 5]
print(my_list)
def modify_list(event):
global my_list
my_list.append(6)
print(my_list)
widget_number = pn.indicators.Number(
name='Number',
value=0,
format='{value}'
)
widget_button_create_list = pn.widgets.Button(name='Create List')
widget_button_create_list.on_click(create_list)
widget_button_modify_list = pn.widgets.Button(name='Modify List')
widget_button_modify_list.on_click(modify_list)
pn.Column(widget_button_create_list, widget_button_modify_list).servable()
Edit: Related questions (turned up in search only after posting):