Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Last active February 9, 2017 10:47
Show Gist options
  • Save mrocklin/46efcd15f88985260ea8cc897cca7664 to your computer and use it in GitHub Desktop.
Save mrocklin/46efcd15f88985260ea8cc897cca7664 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<zmq.eventloop.ioloop.ZMQIOLoop at 0x7fb6cc1896d8>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tornado.ioloop import IOLoop\n",
"loop = IOLoop.current()\n",
"loop"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from bokeh.models import ColumnDataSource\n",
"from bokeh.plotting import figure\n",
"import random\n",
"\n",
"\n",
"def modify_doc(doc):\n",
" source = ColumnDataSource({'x': [], 'y': []}) # Create datasource\n",
" def update():\n",
" source.stream({'x': [random.random()],\n",
" 'y': [random.random()]})\n",
" \n",
" plot = figure(title='my title') # Define figure\n",
" plot.circle(source=source, x='x', y='y')\n",
"\n",
" doc.add_root(plot) # Connect plot to document\n",
"\n",
" doc.add_periodic_callback(update, 100) # Update from stream"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create simple Bokeh server application\n",
"from bokeh.application.handlers import FunctionHandler\n",
"from bokeh.application import Application\n",
"\n",
"handler = FunctionHandler(modify_doc)\n",
"app = Application(handler)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from bokeh.server.server import Server\n",
"server = Server({'/': app}, io_loop=loop, port=5000)\n",
"server.start(start_loop=False)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tornado.access:200 GET / (127.0.0.1) 51.64ms\n",
"INFO:tornado.access:200 GET /static/css/bokeh-widgets.css?v=82b53c925241b5847254f96e42783a01 (127.0.0.1) 14.98ms\n",
"INFO:tornado.access:200 GET /static/js/bokeh.js?v=ae8e146dc909d4a44ee0a4d531d944ea (127.0.0.1) 3.56ms\n",
"INFO:tornado.access:200 GET /static/js/bokeh-widgets.js?v=bcc436544703483c7e5147f572be64bb (127.0.0.1) 2.00ms\n",
"INFO:tornado.access:200 GET /static/css/bokeh.css?v=caeec10a39bd5548fde2c105e5906fdd (127.0.0.1) 1.29ms\n",
"INFO:bokeh.server.views.ws:WebSocket connection opened\n",
"INFO:bokeh.server.views.ws:ServerConnection created\n",
"WARNING:tornado.access:404 GET /favicon.ico (127.0.0.1) 0.61ms\n"
]
}
],
"source": [
"loop._running"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment