There seem to be at at least two or three major ways of building apps that communicate with bokeh-server
in Bokeh. They correspond to the folders app
, embed
and plotting
/glyphs
under the examples directory in Bokeh.
On the differences between them, I read here the following:
On the
stock_app.py
(app
folder) example you are usingbokeh-server
to embed an applet and serve it from the url you specify. That's why you crate a newStockApp
class and create a function that creates a new instance of it and decorates it with @bokeh_app.route("/bokeh/stocks/")
and@object_page("stocks")
. You can follow theapp
examples (sliders, stock and crossfilter) and use bokeh@object_page
and@bokeh_app.route
decorators to create your custom url.On the
taylor_server.py
example (glyphs
folder) it is the session object that is taking care of creating everything onbokeh-server
for you. From this interface is not possible to customize urls or create alias.
But this confused me, what is meant by an "applet" & "embedding" in Bokeh terminology, and what is
exactly he difference between applets (presumably app
and embed
) and plotting
/glyphs
?
Also I thought that the notion of "embedding" only referred to the design pattern that we see in the embed
folder as in the example animated.py
, where we embed a tag
in the body of an HTML file. I don't see that in the stock_app.py
, so why is it an embedding example?
The Bokeh server is an optional component that can be used to provide additional capabilities, such as: hosting and publishing Bokeh plots for wider audiences. streaming data to plots so that they automatically update. interactively visualizing very large datasets by employing downsampling and abstract rendering.
You might want to use the Bokeh server for exploratory data analysis, possibly in a Jupyter notebook, or for a small app that you and your colleagues can run locally.
You can achieve this with the server_document() function. This function accepts the URL to a Bokeh server application and returns a script that embeds a new session from that server every time the script executes. You can add this tag to an HTML page to include the Bokeh application at that point.
But this confused me, what is meant by an "applet" & "embedding" in Bokeh terminology
There is clearly a mistake in the answer you have pasted here (that probably doesn't help you on understanding, sorry). The stock app example stock_app.py
is in examples\app\stock_applet\stock_app.py not embed folder. Also, the terminology used does not help either. On that example you create an applet that can be served in 2 different ways:
You may find more information at the examples\app\stock_applet\README.md
file.
Also, you can find info about applets and bokeh server examples documentation and userguide
Regarding what does embedding means, you can find more info at the user_guide/embedding section of bokeh docs. To summarize, you can generate code that you can insert on your own web application code to display bokeh components. Examples in examples\embed are also useful to understand this pattern.
Finally, the usage of bokeh-server you see in taylor_server.py
is just using bokeh server to serve you plot (instead of saving it to a static html file).
Hope this helps ;-)
Just to add a little bit... I will paste here a quote from Bryan in the mailing list (in another thread, so maybe you missed it):
Regarding app vs embed. The "apps" are all run inside the bokeh-server. So you start them, by doing something like:
bokeh-server --script sliders_app.py
The main reason for this is because, otherwise, to make an "app" outside the server, the only real solutions is to have a long-running process that polls the server for updates. This is not ideal, and apps running directly in the server can utilize much better callbacks. Please note that the "app" concept is still fairly new, and things like how to start, easily spell, and deploy apps is very much open to improvement.
The "embed" examples simply show off how to embed a Bokeh plot in a standard web-app (i.e., you want to serve a plot from Flask that has a plot in it). This can be done with, or without the bokeh-server, but even if you use a bokeh-server, there is no code running in the bokeh-server that responds to widgets, or updates plots or data. To update plots you'd have to have a separate python process that connects to the bokeh-server and polls or pushes data to it.
Cheers.
Damian
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With