I have a matplotlib figure defined:
def cbw_int_plot(CBW_Int):
fig=plt.figure(figsize=(6,6))
plt.title(‘Vsh vs.CBWa’, color = ‘blue’)
#if Sw_quick(m_cem,n_sat,Rw) > 0.8:
plt.plot(logs.vsh,logs.CBWa,‘r.’, label=‘’,color=‘red’)
#plt.plot(logs.vsh,logs.vsh*CBW_Int,‘k-’, label=‘’,color=‘black’)
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(True, which=‘both’,ls=‘-’,color=‘gray’)
plt.grid()
return fig
and if I use Panel in a Jupyter Notebook, I can retrieve the value of CBW_Int with no problems. The code is shown below:
CBW_Int_slider = pn.widgets.FloatSlider(name=‘CBW_Intercept’,start=0,end=0.5,step=0.01,value=0.5)
pn.interact(cbw_int_plot, CBW_Int = CBW_Int_slider)
CBW_Int = CBW_Int_slider.value
This works perfect.
However, in my primary application I need to use the server version as shown below. With my code I cannot obtain the value of CBW_Int. Can you suggest a revision to this code so that I can obtain the CBW_Int value obtained from the Panel widget?
CBW_Int_slider = pn.widgets.FloatSlider(name=‘CBW_Intercept’,start=0,end=0.5,step=0.01,value=0.5)
def button_callback(event):
global CBW_Int
CBW_Int = CBW_Int_slider.value
pn.io.serve(pn).stop()
button = Button(label=“Stop”, button_type=“success”)
button.on_click(button_callback)
pane = pn.interact(cbw_int_plot, CBW_Int = CBW_Int_slider)
def app():
return pn.Row(pn.Column( button, pane[0], width=350, sizing_mode="fixed"), pn.layout.VSpacer(width=10),pane[1])
server = pn.serve({“localhost:”: app}, port=5006)