

#Bokeh examples update#
doc = curdoc () def update ( x, y ): source. We would like to run the app on a Bokeh server, so we execute:įrom functools import partial from random import random from threading import Thread import time from bokeh.models import ColumnDataSource from otting import curdoc, figure from tornado import gen # this must only be modified from a Bokeh session callback source = ColumnDataSource ( data = dict ( x =, y = )) # This is important! Save curdoc() to make sure all threads # see the same document. Get a JSON serialized version of the application. We could, e.g., run bokeh json myapp.py to Theįlexibility of the bokeh command line tool means that we can defer It is a simple script that creates and updates objects. Notice that we have not specified an output or connection method anywhere in on_click ( callback ) # put the button and plot in a layout and add to the document curdoc (). data = new_data i = i + 1 # add a button widget and configure with the call back button = Button ( label = "Press Me" ) button. data in one step with a new dict new_data = dict () new_data = ds.

data_source # create a callback that will add a number in a random location def callback (): global i # BEST PRACTICE - update. text ( x =, y =, text =, text_color =, text_font_size = "20pt", text_baseline = "middle", text_align = "center" ) i = 0 ds = r. grid_line_color = None # add a text renderer to our plot (no data yet) r = p. # myapp.py from random import random from bokeh.layouts import column from bokeh.models import Button from bokeh.palettes import RdYlBu3 from otting import figure, curdoc # create a plot and style its properties p = figure ( x_range = ( 0, 100 ), y_range = ( 0, 100 ), toolbar_location = None ) p. Server with other web application frameworks. Possible with the Bokeh server, but often involves integrating a Bokeh Organization), that can access data or other artifacts published by manyĭifferent people (possibly with access controls). Their own private infrastructure to do so as well, but that is beyond theĪnother possibility is to have a single centrally created app (perhaps by an That we may create a public service to enable just this kind of usage in theįuture, and it would also certainly be possible for third parties to build One approach is to build up infrastructure that can run as many Bokeh serversĪs-needed, either on a per-app, or at least a per-user basis. In order to support this kind of multi-creator, multi-application environment, Security concerns make this kind of shared tenancy prohibitive. Because it is possible toĬreate applications that execute arbitrary python code, process isolation and Is not a good use-case for single Bokeh server. Another scenario is the case where a group of severalĬreators all want publish different applications to the same server. On the server, either for their own local use, or for consumption by a The simple example below, embedded from, illustratesīoth of the scenarios above involve a single creator making applications This capability to synchronize between python and the browser is the main Use periodic, timeout, and asynchronous callbacks to drive streaming updates Respond to UI and tool events generated in a browser with computations orĪutomatically push server-side updates to the UI (i.e. The browser in sync with one another, then more additional and powerful However, if it were possible to keep the “model objects” in python and in The exact same Bokeh plots and visualizations in the browser. (See Defining Key Concepts for a more detailedĭiscussion.) By itself, this flexible and decoupled design offers advantages,įor instance it is easy to have other languages (R, Scala, Lua, …) drive In Python, and then converted to a JSON format that is consumed by theĬlient library, BokehJS. (representing things like plots, ranges, axes, glyphs, etc.) are created The architecture of Bokeh is such that high-level “model objects” Python Callbacks with Jupyter Interactors.
