问题
I dowloaded the repository for Bokeh Crossfilter example from here:
https://github.com/bokeh/bokeh/tree/master/examples/app/crossfilter
It is supposed to generate the interactive plot displayed here:
https://demo.bokeh.org/crossfilter
I ran main.py in the repository. However, nothing appeared. Then I realized the code does not show the layout. So I added the line show(layout) in the end, which did indeed display the layout on a web browser but it would not update the plot when I select different things for x and y axes. I do realize that show(layout) code only shows whatever the layout was at the moment of running the code and it is not telling it to update. However, I couldn't figure out how to show this plot on a web browser so that it is still interactive (would update the plot when I select different axes on the browser).
I would much appreciate any help. Thank you!
回答1:
http://docs.bokeh.org/en/latest/docs/gallery.html In the gallery you can see the first section of examples fall under the bokeh server app category, and require a bokeh server to work interactively.
The second section of examples are standalone (in the browser only).
To run the app corectly: download all the contents of the folder, and save them in the folder, say crossfilter. Open up the command prompt (not in python) and type bokeh serve --show crossfilter. This will open up the app and it should respond to user interaction.
There is a key difference in what can be achieved in running show(layout) from python, and serving a bokeh app from the command line.
Using show(...) will display the content within the browser, from here there is no connection between python and the browser, and therefore no way to update plots from python functions. It can only use javascript (which runs within the browser). There are no javascript callbacks within the crossfilter example, and therefore nothing will happen when you interact with anything.
Bokeh provides a server functionality, which allows code to be run from python and update plots on user interaction. Start from here: http://docs.bokeh.org/en/latest/docs/user_guide/server.html
来源:https://stackoverflow.com/questions/44729057/displaying-bokeh-crossfilter-example