Skip to content

Commit

Permalink
Merge 5b8beef into b4b4abd
Browse files Browse the repository at this point in the history
  • Loading branch information
delsim authored May 18, 2019
2 parents b4b4abd + 5b8beef commit bb1653c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 45 deletions.
139 changes: 100 additions & 39 deletions JupyterDash.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"import dash\n",
"import dash_core_components as dcc\n",
"import dash_html_components as html\n",
"from dash.dependencies import Input, Output, Event\n",
"from dash.dependencies import Input, Output\n",
"\n",
"dd = JupyterDash('SomeID')\n",
"\n",
Expand Down Expand Up @@ -46,12 +46,12 @@
"data": {
"text/html": [
"<div>\n",
" <iframe src=\"/app/endpoints/94c8490f5bbb4ed58b0393901d38f715/\" width=600 height=200 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/94c8490f5bbb4ed58b0393901d38f715/\" target=\"_new\">Open in new window</a> for /app/endpoints/94c8490f5bbb4ed58b0393901d38f715/\n",
" <iframe src=\"/app/endpoints/2f2216256833454083843ddf993755de/\" width=600 height=200 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/2f2216256833454083843ddf993755de/\" target=\"_new\">Open in new window</a> for /app/endpoints/2f2216256833454083843ddf993755de/\n",
"</div>"
],
"text/plain": [
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31ed10e48>"
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44e5bd7518>"
]
},
"execution_count": 3,
Expand All @@ -73,7 +73,7 @@
{
"data": {
"text/plain": [
"'/app/endpoints/94c8490f5bbb4ed58b0393901d38f715/'"
"'/app/endpoints/2f2216256833454083843ddf993755de/'"
]
},
"execution_count": 4,
Expand Down Expand Up @@ -104,7 +104,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -116,10 +116,10 @@
"</div>"
],
"text/plain": [
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31ed10e48>"
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44e5bd7518>"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -130,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -179,7 +179,7 @@
"@a2.expanded_callback(\n",
" dash.dependencies.Output('output-one','children'),\n",
" [dash.dependencies.Input('dropdown-one','value')],\n",
" events = [Event(component_id=\"ticking-interval\", component_event=\"interval\")]\n",
" #events = [Event(component_id=\"ticking-interval\", component_event=\"interval\")]\n",
" )\n",
"def callback_c(*args,**kwargs):\n",
" session_state = kwargs.get('session_state', None)\n",
Expand All @@ -195,22 +195,22 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
" <iframe src=\"/app/endpoints/5687aa1890684b20a59d11f3c0134f6b/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/5687aa1890684b20a59d11f3c0134f6b/\" target=\"_new\">Open in new window</a> for /app/endpoints/5687aa1890684b20a59d11f3c0134f6b/\n",
" <iframe src=\"/app/endpoints/58cceed54a4c4c28988d2d255833b001/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/58cceed54a4c4c28988d2d255833b001/\" target=\"_new\">Open in new window</a> for /app/endpoints/58cceed54a4c4c28988d2d255833b001/\n",
"</div>"
],
"text/plain": [
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31f307320>"
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44c219a160>"
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -222,22 +222,22 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
" <iframe src=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" target=\"_new\">Open in new window</a> for /app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\n",
" <iframe src=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" target=\"_new\">Open in new window</a> for /app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\n",
"</div>"
],
"text/plain": [
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31f307630>"
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44c219a3c8>"
]
},
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -249,7 +249,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -261,22 +261,22 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
" <iframe src=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\" target=\"_new\">Open in new window</a> for /app/endpoints/ee61934d7c804ce1aecb5c596b34eb43/\n",
" <iframe src=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" width=800 height=100 frameborder=\"0\"></iframe>\n",
" <hr/><a href=\"/app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\" target=\"_new\">Open in new window</a> for /app/endpoints/ff6cf46043a848b696a66ffeedcee85b/\n",
"</div>"
],
"text/plain": [
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7ff31f307630>"
"<jupyter_plotly_dash.dash_wrapper.JupyterDash at 0x7f44c219a3c8>"
]
},
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -287,7 +287,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -296,16 +296,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dash_app magic\n",
"feed\n",
"None\n"
]
}
],
"source": [
"%dash_app feed"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -314,18 +324,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{}"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"app.app_state"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e14393b0cbf4489ca495d227ab79f8ee",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Click Me!', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
Expand All @@ -341,18 +377,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dd.app_state"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"config dir: /home/mark/local/jpd/env/etc/jupyter\n",
" jupyter_plotly_dash.serverext \u001b[32m enabled \u001b[0m\n",
" - Validating...\n",
" jupyter_plotly_dash.serverext \u001b[32mOK\u001b[0m\n",
" nbserverproxy \u001b[32m enabled \u001b[0m\n",
" - Validating...\n",
" nbserverproxy \u001b[32mOK\u001b[0m\n"
]
}
],
"source": [
"!jupyter serverextension list"
]
Expand Down Expand Up @@ -381,7 +442,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
11 changes: 9 additions & 2 deletions jupyter_plotly_dash/async_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ async def update(self, request):
da.set_session_state(app_state)
da.handle_current_state()

return web.Response(body=resp.data,
content_type=resp.mimetype)
try:
body = resp.data
content_type = resp.mimetype
except:
body = resp
content_type = "application/json"

return web.Response(body=body,
content_type=content_type)

async def routes(self, request):
print("In routes")
Expand Down
17 changes: 14 additions & 3 deletions jupyter_plotly_dash/dash_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
# along with jupyter-plotly-dash. If not, see <https://www.gnu.org/licenses/>.
#

import uuid
import os

from .async_views import AsyncViews, get_global_av
from .nbkernel import locate_jpd_comm
from django_plotly_dash import DjangoDash
import uuid
import os
from django.conf import settings

settings.configure()

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

return (resp.data.decode('utf-8'), resp.mimetype)
try:
rdata = resp.data
rtype = resp.mimetype
except:
rdata = resp
rtype = "application/json"

return (rdata, rtype)

def rv__dash_component_suites(self, args, app_path, view_name_parts):
return ("<html><body>Requested %s at %s with %s</body></html>" %(args,app_path,view_name_parts),"text/html")
2 changes: 1 addition & 1 deletion jupyter_plotly_dash/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
# along with jupyter-plotly-dash. If not, see <https://www.gnu.org/licenses/>.
#

__version__ = "0.2.0"
__version__ = "0.2.1"

0 comments on commit bb1653c

Please sign in to comment.