Skip to content

Commit 83df1b9

Browse files
delsimGibbsConsulting
authored andcommitted
Updated jpd to work with recent Dash and dpd changes (#35)
* Updated jpd to work with recent Dash and dpd changes * Update python package version
1 parent b4b4abd commit 83df1b9

File tree

4 files changed

+124
-45
lines changed

4 files changed

+124
-45
lines changed

JupyterDash.ipynb

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"import dash\n",
1919
"import dash_core_components as dcc\n",
2020
"import dash_html_components as html\n",
21-
"from dash.dependencies import Input, Output, Event\n",
21+
"from dash.dependencies import Input, Output\n",
2222
"\n",
2323
"dd = JupyterDash('SomeID')\n",
2424
"\n",
@@ -46,12 +46,12 @@
4646
"data": {
4747
"text/html": [
4848
"<div>\n",
49-
" <iframe src=\"/app/endpoints/94c8490f5bbb4ed58b0393901d38f715/\" width=600 height=200 frameborder=\"0\"></iframe>\n",
50-
" <hr/><a href=\"/app/endpoints/94c8490f5bbb4ed58b0393901d38f715/\" target=\"_new\">Open in new window</a> for /app/endpoints/94c8490f5bbb4ed58b0393901d38f715/\n",
49+
" <iframe src=\"/app/endpoints/2f2216256833454083843ddf993755de/\" width=600 height=200 frameborder=\"0\"></iframe>\n",
50+
" <hr/><a href=\"/app/endpoints/2f2216256833454083843ddf993755de/\" target=\"_new\">Open in new window</a> for /app/endpoints/2f2216256833454083843ddf993755de/\n",
5151
"</div>"
5252
],
5353
"text/plain": [
54-
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31ed10e48>"
54+
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44e5bd7518>"
5555
]
5656
},
5757
"execution_count": 3,
@@ -73,7 +73,7 @@
7373
{
7474
"data": {
7575
"text/plain": [
76-
"'/app/endpoints/94c8490f5bbb4ed58b0393901d38f715/'"
76+
"'/app/endpoints/2f2216256833454083843ddf993755de/'"
7777
]
7878
},
7979
"execution_count": 4,
@@ -104,7 +104,7 @@
104104
},
105105
{
106106
"cell_type": "code",
107-
"execution_count": 7,
107+
"execution_count": 6,
108108
"metadata": {},
109109
"outputs": [
110110
{
@@ -116,10 +116,10 @@
116116
"</div>"
117117
],
118118
"text/plain": [
119-
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31ed10e48>"
119+
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44e5bd7518>"
120120
]
121121
},
122-
"execution_count": 7,
122+
"execution_count": 6,
123123
"metadata": {},
124124
"output_type": "execute_result"
125125
}
@@ -130,7 +130,7 @@
130130
},
131131
{
132132
"cell_type": "code",
133-
"execution_count": 8,
133+
"execution_count": 7,
134134
"metadata": {},
135135
"outputs": [],
136136
"source": [
@@ -179,7 +179,7 @@
179179
"@a2.expanded_callback(\n",
180180
" dash.dependencies.Output('output-one','children'),\n",
181181
" [dash.dependencies.Input('dropdown-one','value')],\n",
182-
" events = [Event(component_id=\"ticking-interval\", component_event=\"interval\")]\n",
182+
" #events = [Event(component_id=\"ticking-interval\", component_event=\"interval\")]\n",
183183
" )\n",
184184
"def callback_c(*args,**kwargs):\n",
185185
" session_state = kwargs.get('session_state', None)\n",
@@ -195,22 +195,22 @@
195195
},
196196
{
197197
"cell_type": "code",
198-
"execution_count": 9,
198+
"execution_count": 8,
199199
"metadata": {},
200200
"outputs": [
201201
{
202202
"data": {
203203
"text/html": [
204204
"<div>\n",
205-
" <iframe src=\"/app/endpoints/5687aa1890684b20a59d11f3c0134f6b/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
206-
" <hr/><a href=\"/app/endpoints/5687aa1890684b20a59d11f3c0134f6b/\" target=\"_new\">Open in new window</a> for /app/endpoints/5687aa1890684b20a59d11f3c0134f6b/\n",
205+
" <iframe src=\"/app/endpoints/58cceed54a4c4c28988d2d255833b001/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
206+
" <hr/><a href=\"/app/endpoints/58cceed54a4c4c28988d2d255833b001/\" target=\"_new\">Open in new window</a> for /app/endpoints/58cceed54a4c4c28988d2d255833b001/\n",
207207
"</div>"
208208
],
209209
"text/plain": [
210-
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31f307320>"
210+
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44c219a160>"
211211
]
212212
},
213-
"execution_count": 9,
213+
"execution_count": 8,
214214
"metadata": {},
215215
"output_type": "execute_result"
216216
}
@@ -222,22 +222,22 @@
222222
},
223223
{
224224
"cell_type": "code",
225-
"execution_count": 10,
225+
"execution_count": 9,
226226
"metadata": {},
227227
"outputs": [
228228
{
229229
"data": {
230230
"text/html": [
231231
"<div>\n",
232-
" <iframe src=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
233-
" <hr/><a href=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" target=\"_new\">Open in new window</a> for /app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\n",
232+
" <iframe src=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
233+
" <hr/><a href=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" target=\"_new\">Open in new window</a> for /app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\n",
234234
"</div>"
235235
],
236236
"text/plain": [
237-
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31f307630>"
237+
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44c219a3c8>"
238238
]
239239
},
240-
"execution_count": 10,
240+
"execution_count": 9,
241241
"metadata": {},
242242
"output_type": "execute_result"
243243
}
@@ -249,7 +249,7 @@
249249
},
250250
{
251251
"cell_type": "code",
252-
"execution_count": 11,
252+
"execution_count": 10,
253253
"metadata": {},
254254
"outputs": [],
255255
"source": [
@@ -261,22 +261,22 @@
261261
},
262262
{
263263
"cell_type": "code",
264-
"execution_count": 12,
264+
"execution_count": 11,
265265
"metadata": {},
266266
"outputs": [
267267
{
268268
"data": {
269269
"text/html": [
270270
"<div>\n",
271-
" <iframe src=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
272-
" <hr/><a href=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" target=\"_new\">Open in new window</a> for /app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\n",
271+
" <iframe src=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
272+
" <hr/><a href=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" target=\"_new\">Open in new window</a> for /app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\n",
273273
"</div>"
274274
],
275275
"text/plain": [
276-
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31f307630>"
276+
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44c219a3c8>"
277277
]
278278
},
279-
"execution_count": 12,
279+
"execution_count": 11,
280280
"metadata": {},
281281
"output_type": "execute_result"
282282
}
@@ -287,7 +287,7 @@
287287
},
288288
{
289289
"cell_type": "code",
290-
"execution_count": null,
290+
"execution_count": 12,
291291
"metadata": {},
292292
"outputs": [],
293293
"source": [
@@ -296,16 +296,26 @@
296296
},
297297
{
298298
"cell_type": "code",
299-
"execution_count": null,
299+
"execution_count": 13,
300300
"metadata": {},
301-
"outputs": [],
301+
"outputs": [
302+
{
303+
"name": "stdout",
304+
"output_type": "stream",
305+
"text": [
306+
"dash_app magic\n",
307+
"feed\n",
308+
"None\n"
309+
]
310+
}
311+
],
302312
"source": [
303313
"%dash_app feed"
304314
]
305315
},
306316
{
307317
"cell_type": "code",
308-
"execution_count": null,
318+
"execution_count": 14,
309319
"metadata": {},
310320
"outputs": [],
311321
"source": [
@@ -314,18 +324,44 @@
314324
},
315325
{
316326
"cell_type": "code",
317-
"execution_count": null,
327+
"execution_count": 15,
318328
"metadata": {},
319-
"outputs": [],
329+
"outputs": [
330+
{
331+
"data": {
332+
"text/plain": [
333+
"{}"
334+
]
335+
},
336+
"execution_count": 15,
337+
"metadata": {},
338+
"output_type": "execute_result"
339+
}
340+
],
320341
"source": [
321342
"app.app_state"
322343
]
323344
},
324345
{
325346
"cell_type": "code",
326-
"execution_count": null,
347+
"execution_count": 16,
327348
"metadata": {},
328-
"outputs": [],
349+
"outputs": [
350+
{
351+
"data": {
352+
"application/vnd.jupyter.widget-view+json": {
353+
"model_id": "e14393b0cbf4489ca495d227ab79f8ee",
354+
"version_major": 2,
355+
"version_minor": 0
356+
},
357+
"text/plain": [
358+
"Button(description='Click Me!', style=ButtonStyle())"
359+
]
360+
},
361+
"metadata": {},
362+
"output_type": "display_data"
363+
}
364+
],
329365
"source": [
330366
"import ipywidgets as widgets\n",
331367
"from IPython.display import display\n",
@@ -341,18 +377,43 @@
341377
},
342378
{
343379
"cell_type": "code",
344-
"execution_count": null,
380+
"execution_count": 17,
345381
"metadata": {},
346-
"outputs": [],
382+
"outputs": [
383+
{
384+
"data": {
385+
"text/plain": [
386+
"{}"
387+
]
388+
},
389+
"execution_count": 17,
390+
"metadata": {},
391+
"output_type": "execute_result"
392+
}
393+
],
347394
"source": [
348395
"dd.app_state"
349396
]
350397
},
351398
{
352399
"cell_type": "code",
353-
"execution_count": null,
400+
"execution_count": 18,
354401
"metadata": {},
355-
"outputs": [],
402+
"outputs": [
403+
{
404+
"name": "stdout",
405+
"output_type": "stream",
406+
"text": [
407+
"config dir: /home/mark/local/jpd/env/etc/jupyter\n",
408+
" jupyter_plotly_dash.serverext \u001b[32m enabled \u001b[0m\n",
409+
" - Validating...\n",
410+
" jupyter_plotly_dash.serverext \u001b[32mOK\u001b[0m\n",
411+
" nbserverproxy \u001b[32m enabled \u001b[0m\n",
412+
" - Validating...\n",
413+
" nbserverproxy \u001b[32mOK\u001b[0m\n"
414+
]
415+
}
416+
],
356417
"source": [
357418
"!jupyter serverextension list"
358419
]
@@ -381,7 +442,7 @@
381442
"name": "python",
382443
"nbconvert_exporter": "python",
383444
"pygments_lexer": "ipython3",
384-
"version": "3.6.5"
445+
"version": "3.6.8"
385446
}
386447
},
387448
"nbformat": 4,

jupyter_plotly_dash/async_views.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ async def update(self, request):
107107
da.set_session_state(app_state)
108108
da.handle_current_state()
109109

110-
return web.Response(body=resp.data,
111-
content_type=resp.mimetype)
110+
try:
111+
body = resp.data
112+
content_type = resp.mimetype
113+
except:
114+
body = resp
115+
content_type = "application/json"
116+
117+
return web.Response(body=body,
118+
content_type=content_type)
112119

113120
async def routes(self, request):
114121
print("In routes")

jupyter_plotly_dash/dash_wrapper.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
# along with jupyter-plotly-dash. If not, see <https://www.gnu.org/licenses/>.
2020
#
2121

22+
import uuid
23+
import os
24+
2225
from .async_views import AsyncViews, get_global_av
2326
from .nbkernel import locate_jpd_comm
2427
from django_plotly_dash import DjangoDash
25-
import uuid
26-
import os
28+
from django.conf import settings
29+
30+
settings.configure()
2731

2832
class JupyterDash:
2933
def __init__(self, name, gav=None, width=800, height=600):
@@ -184,7 +188,14 @@ def rv__dash_update_component(self, args, app_path, view_name_parts):
184188
self.set_session_state(app_state)
185189
self.handle_current_state()
186190

187-
return (resp.data.decode('utf-8'), resp.mimetype)
191+
try:
192+
rdata = resp.data
193+
rtype = resp.mimetype
194+
except:
195+
rdata = resp
196+
rtype = "application/json"
197+
198+
return (rdata, rtype)
188199

189200
def rv__dash_component_suites(self, args, app_path, view_name_parts):
190201
return ("<html><body>Requested %s at %s with %s</body></html>" %(args,app_path,view_name_parts),"text/html")

jupyter_plotly_dash/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# along with jupyter-plotly-dash. If not, see <https://www.gnu.org/licenses/>.
2020
#
2121

22-
__version__ = "0.2.0"
22+
__version__ = "0.2.1"

0 commit comments

Comments
 (0)