Skip to content

Commit f28df75

Browse files
committed
adding run button to widgets playground
1 parent 99171f8 commit f28df75

File tree

1 file changed

+57
-44
lines changed

1 file changed

+57
-44
lines changed

examples/widgets_playground.ipynb

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 1,
14+
"execution_count": 25,
1515
"metadata": {},
16-
"outputs": [],
16+
"outputs": [
17+
{
18+
"name": "stderr",
19+
"output_type": "stream",
20+
"text": [
21+
"WARNING: You are using pip version 21.2.3; however, version 22.1.2 is available.\n",
22+
"You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.\n",
23+
"WARNING: You are using pip version 21.2.3; however, version 22.1.2 is available.\n",
24+
"You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.\n"
25+
]
26+
}
27+
],
1728
"source": [
1829
"import sys\n",
1930
"import subprocess\n",
@@ -31,19 +42,26 @@
3142
},
3243
{
3344
"cell_type": "code",
34-
"execution_count": 2,
45+
"execution_count": 26,
3546
"metadata": {},
3647
"outputs": [],
3748
"source": [
38-
"from ipywidgets import Tab, SelectMultiple, IntSlider, FloatSlider, HBox, VBox, Output\n",
49+
"from ipywidgets import Tab, SelectMultiple, IntSlider, FloatSlider, HBox, VBox, Output, Button\n",
3950
"from matplotlib import pyplot\n",
4051
"from IPython.display import display, clear_output\n",
4152
"import PyPartMC as ppmc"
4253
]
4354
},
4455
{
4556
"cell_type": "code",
46-
"execution_count": 3,
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": []
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 27,
4765
"metadata": {},
4866
"outputs": [],
4967
"source": [
@@ -53,7 +71,7 @@
5371
},
5472
{
5573
"cell_type": "code",
56-
"execution_count": 4,
74+
"execution_count": 28,
5775
"metadata": {},
5876
"outputs": [],
5977
"source": [
@@ -62,17 +80,19 @@
6280
},
6381
{
6482
"cell_type": "code",
65-
"execution_count": 5,
83+
"execution_count": 29,
6684
"metadata": {},
6785
"outputs": [],
6886
"source": [
6987
"param_x_widget = IntSlider(description='x [1]', min=1, max=9, value=2)\n",
70-
"param_y_widget = IntSlider(description='y [1]', min=0, max=3, value=2)"
88+
"param_y_widget = IntSlider(description='y [1]', min=0, max=3, value=2)\n",
89+
"button = Button(description= 'Run')\n",
90+
"output = Output()"
7191
]
7292
},
7393
{
7494
"cell_type": "code",
75-
"execution_count": 6,
95+
"execution_count": 30,
7696
"metadata": {},
7797
"outputs": [],
7898
"source": [
@@ -96,7 +116,7 @@
96116
},
97117
{
98118
"cell_type": "code",
99-
"execution_count": 7,
119+
"execution_count": 33,
100120
"metadata": {},
101121
"outputs": [],
102122
"source": [
@@ -112,67 +132,55 @@
112132
")\n",
113133
"tabs.set_title(0, \"GasData\")\n",
114134
"tabs.set_title(1, \"Scenario\")\n",
115-
"tabs.set_title(2, \"AeroState\")"
135+
"tabs.set_title(2, \"AeroState\")\n",
136+
"gui = VBox((tabs,button,output))\n",
137+
"def action(_):\n",
138+
" with output:\n",
139+
" clear_output(wait=True)\n",
140+
" print(param_x_widget.value, \",\", param_y_widget.value)\n",
141+
" gas_data = ppmc.GasData(gas_data_widget.value)\n",
142+
" print(gas_data)\n",
143+
"\n",
144+
"button.on_click(action)\n"
116145
]
117146
},
118147
{
119148
"cell_type": "code",
120-
"execution_count": 8,
149+
"execution_count": 34,
121150
"metadata": {},
122151
"outputs": [
123152
{
124153
"data": {
125154
"application/vnd.jupyter.widget-view+json": {
126-
"model_id": "2e539a71b14b40c2b96933a5398b2fd9",
155+
"model_id": "761d1bf26db842a2b8f9c1bbc72234e6",
127156
"version_major": 2,
128157
"version_minor": 0
129158
},
130159
"text/plain": [
131-
"Tab(children=(SelectMultiple(index=(0, 1, 2, 3, 4, 5), options=('H2SO4', 'HNO3', 'HCl', 'NH3', 'NO', 'NO2'), v"
160+
"VBox(children=(Tab(children=(SelectMultiple(index=(1,), options=('H2SO4', 'HNO3', 'HCl', 'NH3', 'NO', 'NO2'), …"
132161
]
133162
},
134163
"metadata": {},
135164
"output_type": "display_data"
136165
}
137166
],
138167
"source": [
139-
"display(tabs)"
168+
"display(gui)"
140169
]
141170
},
142171
{
143172
"cell_type": "code",
144-
"execution_count": 9,
173+
"execution_count": null,
145174
"metadata": {},
146-
"outputs": [
147-
{
148-
"name": "stdout",
149-
"output_type": "stream",
150-
"text": [
151-
"2 , 2\n"
152-
]
153-
}
154-
],
155-
"source": [
156-
"print(param_x_widget.value, \",\", param_y_widget.value)"
157-
]
175+
"outputs": [],
176+
"source": []
158177
},
159178
{
160179
"cell_type": "code",
161-
"execution_count": 10,
180+
"execution_count": null,
162181
"metadata": {},
163-
"outputs": [
164-
{
165-
"name": "stdout",
166-
"output_type": "stream",
167-
"text": [
168-
"[\"H2SO4\",\"HNO3\",\"HCl\",\"NH3\",\"NO\",\"NO2\"]\n"
169-
]
170-
}
171-
],
172-
"source": [
173-
"gas_data = ppmc.GasData(gas_data_widget.value)\n",
174-
"print(gas_data)"
175-
]
182+
"outputs": [],
183+
"source": []
176184
},
177185
{
178186
"cell_type": "code",
@@ -191,7 +199,7 @@
191199
],
192200
"metadata": {
193201
"kernelspec": {
194-
"display_name": "Python 3",
202+
"display_name": "Python 3.10.0 64-bit",
195203
"language": "python",
196204
"name": "python3"
197205
},
@@ -205,7 +213,12 @@
205213
"name": "python",
206214
"nbconvert_exporter": "python",
207215
"pygments_lexer": "ipython3",
208-
"version": "3.8.7"
216+
"version": "3.10.0"
217+
},
218+
"vscode": {
219+
"interpreter": {
220+
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
221+
}
209222
}
210223
},
211224
"nbformat": 4,

0 commit comments

Comments
 (0)