Spaces:
Sleeping
Sleeping
| from webworld_lib import * | |
| pn.extension("tabulator") | |
| ACCENT = "indigo" | |
| styles = { | |
| "box-shadow": "rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px", | |
| "border-radius": "4px", | |
| "padding": "10px", | |
| } | |
| CSS = """ | |
| div.card-margin:nth-child(1) { | |
| max-height: 280px; | |
| } | |
| } | |
| """ | |
| fixed_data = fixed_parameters() | |
| global Nt, SN; | |
| Nt =0.0; Tn = 0.0 | |
| MS = fixed_data[0] | |
| R = fixed_data[1] | |
| c= fixed_data[2] | |
| ld = fixed_data[3] | |
| Ng = fixed_data[4] | |
| L = fixed_data[5] | |
| K = fixed_data[6] | |
| b = fixed_data[7] | |
| Running = False | |
| # Parameter Values | |
| t_comp = pn.widgets.FloatSlider(value= c ,start=0.1, | |
| end=0.9, step=0.1, | |
| name='Competition') | |
| t_res = pn.widgets.FloatSlider(value= R ,start=1e4, | |
| end=1e6, step=1e4, | |
| name='Resources') | |
| figa = ( | |
| pd.DataFrame([],columns=['SN']) | |
| ).hvplot( | |
| title="Number of Species", | |
| ylabel="Number of Species", | |
| xlabel="Evolutionary event", | |
| #xlim=(0, Ng), | |
| autorange = "y", | |
| color=ACCENT, | |
| ) | |
| #print(figa) | |
| FW = nx.DiGraph() | |
| figb = hvnx.draw(FW, with_labels=True) | |
| pr1 = pn.pane.Str( | |
| 'Static parameters (K,L):'+str(K)+' '+str(L) | |
| ) | |
| pr2 = pn.pane.Str('Max number of allowed species: '+str(MS)) | |
| pr3 = pn.pane.Str('Number of evolutionary steps: '+str(Ng)) | |
| pr4 = pn.pane.Str('b: '+str(b)) | |
| #pr3 = pn.pane.Str('Ready') | |
| button = pn.widgets.Button(name='\u25b6',description='Run') | |
| #print(button.name) | |
| # Display Data | |
| indicators = pn.FlexBox( | |
| pn.indicators.Number( | |
| value=t_res, name="External Resources", | |
| format="{value:,.1E}", | |
| font_size = "5", | |
| title_size = "6", | |
| styles=styles | |
| ), | |
| pn.indicators.Number( | |
| value=t_comp, | |
| name="Competition parameter", | |
| format="{value:,.1f}", | |
| font_size = "5", | |
| title_size = "6", | |
| styles=styles, | |
| ), | |
| pn.indicators.Number( | |
| value=Tn, | |
| name="Time", | |
| format="{value:,.1f}", | |
| font_size = "5", | |
| title_size = "6", | |
| styles=styles, | |
| ), | |
| pn.indicators.Number( | |
| value=Nt, | |
| name="Number of Species", | |
| font_size = "5", | |
| title_size = "6", | |
| format="{value:,.1f}", | |
| styles=styles, | |
| ), | |
| ) | |
| Pt = np.array([MS,t_res.value,t_comp.value,ld,Ng,L,K,b,indicators[3],indicators[2]]) | |
| plotns = pn.pane.HoloViews(figa, sizing_mode="stretch_both", name="PlotNS") | |
| plotfw = pn.pane.HoloViews(figb, sizing_mode="stretch_both", name="PlotFW") | |
| tabs = pn.Tabs( | |
| plotns, plotfw, styles=styles, sizing_mode="stretch_width", height=500, margin=10 | |
| ) | |
| ly1 = pn.Column(pr1, pr2, pr3, pr4,t_comp,t_res, button, sizing_mode="stretch_both") | |
| ly2 = pn.Column(indicators, tabs, sizing_mode="stretch_both") | |
| button.on_click(partial(start_sim,Pt,[t_res,t_comp],button,tabs)) | |
| pn.template.FastListTemplate( | |
| title="Webworld Model Demo", | |
| main=[ly1,ly2], | |
| main_layout=None, | |
| accent=ACCENT, | |
| raw_css=[CSS] | |
| ).servable() |