I have a piece of panel code that sort of works. My goal is to some how save the constant CBW_Int that I pick from the panel server. I cannot seem to pass this on automatically so that I could then use this constant after the interactive widget work. Is there a way to do this:
import panel as pn
import matplotlib.pyplot as plt
import numpy as np
from bokeh.models.widgets import Button
CBW_Int = 0.25 # Define CBW_Int as a global variable
CBW_Int_slider = pn.widgets.FloatSlider(name=‘CBW_Intercept’, start=0, end=0.5, step=0.01, value=CBW_Int)
def cbw_int_plot(plot=True):
global CBW_Int # Access the global CBW_Int variable
fig = plt.figure(figsize=(6, 6))
plt.title('Vsh vs.CBWa', color='blue')
plt.plot(np.arange(10), np.arange(10) * CBW_Int, "k-", label="")
plt.xlim(0.0, 1)
plt.ylim(0.0, 1.0)
plt.ylabel('CBWa [v/v]', color='blue')
plt.xlabel('Vsh [v/v]', color='blue')
plt.grid()
if plot:
plt.show()
else:
plt.close(fig)
return fig
def button_callback(event):
global CBW_Int
CBW_Int = CBW_Int_slider.value
# Save the new CBW_Int value to a file
with open("new_cbw_int.txt", "w") as f:
f.write(str(CBW_Int))
#pn.io.server_stop()
pn.io.serve(pn).stop()
button = Button(label=“Stop”, button_type=“success”)
button.on_click(button_callback)
def plot_update():
fig = cbw_int_plot(plot=False)
return pn.pane.Matplotlib(fig)
def app():
return pn.Column(
button,
pn.Row(CBW_Int_slider),
plot_update,
)
pn.serve({“localhost:”: app}, port=5006)