Skip to content

Commit

Permalink
lantern live working
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Jan 30, 2018
1 parent 7e0be4d commit c051d96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 72 deletions.
80 changes: 11 additions & 69 deletions examples/live.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
"\n",
" <div class=\"bk-root\">\n",
" <a href=\"https://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
" <span id=\"25c3b7fb-8f92-4480-b75e-e8322985a998\">Loading BokehJS ...</span>\n",
" <span id=\"3e3ff19d-30fe-49e2-84e1-719df9a24920\">Loading BokehJS ...</span>\n",
" </div>"
]
},
Expand Down Expand Up @@ -376,7 +376,7 @@
" \"</div>\"}};\n",
"\n",
" function display_loaded() {\n",
" var el = document.getElementById(\"25c3b7fb-8f92-4480-b75e-e8322985a998\");\n",
" var el = document.getElementById(\"3e3ff19d-30fe-49e2-84e1-719df9a24920\");\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS is loading...\";\n",
" }\n",
Expand Down Expand Up @@ -430,9 +430,9 @@
" console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" }\n",
" };var element = document.getElementById(\"25c3b7fb-8f92-4480-b75e-e8322985a998\");\n",
" };var element = document.getElementById(\"3e3ff19d-30fe-49e2-84e1-719df9a24920\");\n",
" if (element == null) {\n",
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid '25c3b7fb-8f92-4480-b75e-e8322985a998' but no matching script tag was found. \")\n",
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid '3e3ff19d-30fe-49e2-84e1-719df9a24920' but no matching script tag was found. \")\n",
" return false;\n",
" }\n",
"\n",
Expand Down Expand Up @@ -469,7 +469,7 @@
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
" root._bokeh_failed_load = true;\n",
" } else if (force !== true) {\n",
" var cell = $(document.getElementById(\"25c3b7fb-8f92-4480-b75e-e8322985a998\")).parents('.cell').data().cell;\n",
" var cell = $(document.getElementById(\"3e3ff19d-30fe-49e2-84e1-719df9a24920\")).parents('.cell').data().cell;\n",
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
" }\n",
"\n",
Expand All @@ -486,7 +486,7 @@
" }\n",
"}(window));"
],
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"25c3b7fb-8f92-4480-b75e-e8322985a998\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n }\n finally {\n delete root._bokeh_onload_callbacks\n }\n console.info(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(js_urls, callback) {\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = js_urls.length;\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var s = document.createElement('script');\n s.src = url;\n s.async = false;\n s.onreadystatechange = s.onload = function() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: all BokehJS libraries loaded\");\n run_callbacks()\n }\n };\n s.onerror = function() {\n console.warn(\"failed to load library \" + url);\n };\n console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.getElementsByTagName(\"head\")[0].appendChild(s);\n }\n };var element = document.getElementById(\"25c3b7fb-8f92-4480-b75e-e8322985a998\");\n if (element == null) {\n console.log(\"Bokeh: ERROR: autoload.js configured with elementid '25c3b7fb-8f92-4480-b75e-e8322985a998' but no matching script tag was found. \")\n return false;\n }\n\n var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.10.min.js\"];\n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n \n function(Bokeh) {\n \n },\n function(Bokeh) {\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n }\n ];\n\n function run_inline_js() {\n \n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"25c3b7fb-8f92-4480-b75e-e8322985a998\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(js_urls, function() {\n console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));"
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"3e3ff19d-30fe-49e2-84e1-719df9a24920\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n }\n finally {\n delete root._bokeh_onload_callbacks\n }\n console.info(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(js_urls, callback) {\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = js_urls.length;\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var s = document.createElement('script');\n s.src = url;\n s.async = false;\n s.onreadystatechange = s.onload = function() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: all BokehJS libraries loaded\");\n run_callbacks()\n }\n };\n s.onerror = function() {\n console.warn(\"failed to load library \" + url);\n };\n console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.getElementsByTagName(\"head\")[0].appendChild(s);\n }\n };var element = document.getElementById(\"3e3ff19d-30fe-49e2-84e1-719df9a24920\");\n if (element == null) {\n console.log(\"Bokeh: ERROR: autoload.js configured with elementid '3e3ff19d-30fe-49e2-84e1-719df9a24920' but no matching script tag was found. \")\n return false;\n }\n\n var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.10.min.js\"];\n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n \n function(Bokeh) {\n \n },\n function(Bokeh) {\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n }\n ];\n\n function run_inline_js() {\n \n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"3e3ff19d-30fe-49e2-84e1-719df9a24920\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(js_urls, function() {\n console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));"
},
"metadata": {},
"output_type": "display_data"
Expand Down Expand Up @@ -544,7 +544,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:root:adding handler lantern.live on 0\n"
"INFO:root:adding handler lantern.live..0\n"
]
}
],
Expand All @@ -560,7 +560,7 @@
{
"data": {
"text/plain": [
"comm://b4a395da-9e7e-4e93-a1d3-6ad67bbf02df/0"
"comm://1c5d1ff6-a323-41f5-814f-88283923788c/0"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -588,7 +588,7 @@
"outputs": [
{
"data": {
"application/psp": "comm://b4a395da-9e7e-4e93-a1d3-6ad67bbf02df/0"
"application/psp": "comm://1c5d1ff6-a323-41f5-814f-88283923788c/0"
},
"metadata": {},
"output_type": "display_data"
Expand All @@ -600,72 +600,14 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n",
"CRITICAL:root:sleeping\n"
]
}
],
"outputs": [],
"source": [
"# import lantern as l\n",
"# df = l.bar.sample()\n",
"# psp(df.to_json(orient='records'))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"ip = get_ipython()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def f(comm, msg):\n",
" comm.send({'test':1})\n",
"ip.kernel.comm_manager.register_target('lanternlive-0', f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
6 changes: 3 additions & 3 deletions lantern/live/hosts/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def handle_open(comm, msg):
comm.on_close = on_close
self.comm = comm

get_ipython().kernel.comm_manager.register_target('lantern.live', handle_open)
get_ipython().kernel.comm_manager.register_target('lantern.live.' + str(channel), handle_open)

def run(self):
# TODO wait until JS ready
Expand All @@ -33,10 +33,10 @@ def run(self):

if message != '[]':
self.comm.send(data=message)
time.sleep(5)
time.sleep(1)


def runComm(q, channel):
logging.info('adding handler %s on %s' % ('lantern.live', channel))
logging.info('adding handler %s.%s' % ('lantern.live.', channel))
comm = CommHandler(q, channel)
comm.run()
5 changes: 5 additions & 0 deletions lantern/live/sources/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

class RandomSource(Streaming):
def run(self):
self.cols = None
while True:
df = l.bar.sample()
if self.cols is None:
self.cols = df.columns
else:
df.columns = self.cols
for i in range(len(df)):
# logging.info(df.iloc[i].to_json())
self.on_data(df.iloc[i].to_json())
Expand Down

0 comments on commit c051d96

Please sign in to comment.