Bokeh in web app - generate plots on server (Bokeh) or client (BokehJS)?

Backgroud: consumer data visualization app, scaling from a prototype to production.

Current setup: Front-end (React) takes some user input (say car make and model) and sends it to the backend as POST request. Backend (python/FastAPI) parses the request, runs some DB queries and calculations, generates a Bokeh plot and sends it to the frontend as JSON/string. The frontend shows this JSON in its specified div, and we’re done. If the plot requires callbacks, they are implemented as CustomJS, with the callback again hitting that same API (with new args collected from the page, as needed), getting JSON and replacing the current plot with the newly received one.

Contemplated alternative setup:
Backend sends only data and Bokeh plot is generated on the client side with BokehJS.

Questions

  1. What are pros and cons of the alternative?
  2. How does the JS interface of Bokeh compare to Python, in terms of:
    • maturity
    • documentation
    • features
    • flexibility
    • performance
    • anything else?
  3. Will it be harder or easier to maintain, extend, abstract/refactor these plots in JS as compared to Python?
  4. Is client- or server-side plot generation better suited to our use case where user interactions are not visual (natively supported by Bokeh like scroll etc.) but require new data from the server?
  5. Anything else we need to know?

Any advice would be much appreciated. :pray:

(the question is also on SO)

Every feature or capability that (Python) Bokeh affords is ultimately actually implemented by BokehJS. So the short answer is that there is no difference at all in features or flexibility or performance (modulo any differences between your serialization overhead and Bokeh’s).

All of the differences really come down to maturity and documentation, with come caveats:

  • There is an exact 1-1 correspondence maintained for all Bokeh models and properties, and this is strictly maintained under continuous test. i.e. a Python DataRange1d and a BokehJS DataRange1d will always have the same properties, with the same default values. So you can rely on the “bokeh.models” JS API and you could reasonably use the Python reference as a BokehJS reference in this sense.

  • There’s also a partial clone of “bokeh.plotting” in BokehJS (in a separate bokeh-api.js bundle), this is probably fairly stable, but again you’d need to rely on Python docs as a starting point. But the BokehJS version of “bokeh.plotting” does not currently have full parity with the Python API.

  • BokehJS is still under very heavy development, and the rest of the API that is not models/properties or bokeh-api.js is not nearly as stable nor really documented at all. That’s probably mostly fine, all of the rest of BokehJS should really probably be considered private implementation.

  • All of the existing BokehJS docs are really just what’s on this page: BokehJS — Bokeh 3.2.1 Documentation Notably absent is any specific guidance for integrating BokehJS with node applications or popular frameworks like React or Vue.

FWIW I think promoting BokehJS as a first-class JavaScript library in its own right would be one of the very best things that could happen for the project. But speaking completely frankly, I don’t think that will happen until/unless some experienced JS front-end devs, with strong opinions about what a good front-end JS library looks like [1], to decide to get involved at a significant level.

All that said, people can and do already use BokehJS directly with success, but there may be some initial costs to figure out how best to integrate it in your project.

cc @mateusz for any further comments


  1. what kind of documentation do JS dev want/expect? What (public) APIs are missing e.g. to help embed BokehJS content? What is missing for buld/packaging? In case you can’t tell, none of use are really front-end devs, and it shows. ↩︎

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.