Best practices for embedding Bokeh Charts in a webapp (embedding vs applets)

I’m wondering in which situation is it better to use applets vs embedding (considering the case of a webapp), and what are the limits of each approach.

After reading the doc (this section of the user_guide & and the examples and these SO questions (one, two)) - there’s still a couple of dark spots for me.

Applets feel overall better (performance, can do dynamic plots with plotting interface), but i have two concerns about them :

  1. Is it advisable to use applets for a multi-page web app ? In that case, should we have one bokeh-server instance per page, with it’s own script ?

  2. It does not seem possible to do per component integration in html - it’s just one single block of js (because we receive only one tag _tag). correct ?

Currently i’m using embedding - it was easy to start as there were many examples.

The drawback of embedding is that it doesn’t seem possible to do dynamic plots using the plotting interface - I haven’t seen any example doing that. Is that correct, or am I missing something ?

Thanks,

Nicolas

Hi Nicolas,

Thanks for your good questions. First I wanted to mention that I have started work on a new Users Guide which will have much better information and examples around embedding, server apps, etc.

The main advantage of a server app is the two way communication between the python code and app in the browser. In particular, if you want to:

1) react and respond to changes in plot selections

or

2) use Bokeh's widgets and react and respond to changes in those

Then a server app is really the only route to go. If neither of these things is true, then you could do a server app, but it's not required. If you just want to push data to update a plot, for instance, you can embed it using:

  autoload_server(...)

And then another process (probably your flask or django app) can update the data, which will cause the plot to update.

Regarding the server, you should need one at most. There are ways to run multiple scripts in one server. The easiest it probably just to import the other modules in a new .py file, and use that .py file as your script. If you are using the server in multi-user mode there are config files. Let me know and I can get you more info while I am still working on the docs.

It's also possible to embed and update using embed.components, but it is much more "coarse grained". This is going to generate and send the entire plot object every time. There are times when this is perfectly fine. You are correct that if you put several plots into a layout and call embed.components on the entire layout, then you give up control over rendering the plots individually. You could certainly call embed.components on each individual plot (getting a tag for each), but then you are going to have to layout the plots yourself when you render the page, or do some kind of partial page update.

There are probably other questions generated by this but let me stop here and see if what I've already said makes sense.

Bryan

···

On Mar 11, 2015, at 2:03 AM, [email protected] wrote:

I'm wondering in which situation is it better to use applets vs embedding (considering the case of a webapp), and what are the limits of each approach.

After reading the doc (this section of the user_guide & and the examples and these SO questions (one, two)) - there's still a couple of dark spots for me.

Applets feel overall better (performance, can do dynamic plots with plotting interface), but i have two concerns about them :
1. Is it advisable to use applets for a multi-page web app ? In that case, should we have one bokeh-server instance per page, with it's own script ?
2. It does not seem possible to do per component integration in html - it's just one single block of js (because we receive only one tag `_tag`). correct ?

Currently i'm using embedding - it was easy to start as there were many examples.
The drawback of embedding is that it doesn't seem possible to do dynamic plots using the plotting interface - I haven't seen any example doing that. Is that correct, or am I missing something ?

Thanks,
Nicolas

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9da63a55-15ff-473b-99de-e52a17838da5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for this detailed answer Bryan !

It is super useful, but as you guessed, it generates a few more questions.

I have a functional web app (3 pages with each its own bokeh plot) that is making great use of point #2 (changing displayed data based on a bokeh dropdown selection). It was built using the data_tables_server example as a guide.

The two immediate questions / reactions that come to mind are :

  1. As I’ve reused the general infrastructure of data_tables_server.py, I’ve used the models interface for all my plots. I’d like to switch to the plotting interface to be able to create new plots faster. Is that possible within the embedding framework i’m using, or is it necessary that i switch to the applet style ? Guidance on this point would be great. I don’t understand if it’s something trivial or extremely hard.

  2. The paragraph where you confirm that it’s possible to run multiple scripts in one server is super useful. The way i interprete it is that using applets is both more efficient (performance wise), easier to code (plotting interface), can be used to generate multiple plots that can be integrated on different pages. So to make a dashboard web app, applets would be an overall better solution, correct ?

I’m still trying to wrap my head around the last paragraph. I haven’t paid attention to embed.components before. I’ve had a very quick read-through of the doc, i need to read it a bit more in depth before asking questions.

Nicolas

PS :

I’ve spent the past 3 weeks or so coming from complete beginner to able to make stuff works in embedding / bokeh-server, so i think i have in mind most of the hurdles that a newcomer to bokeh will face. I’d be happy to give you feedback on the User Guide draft you’re working on.

···

On Wednesday, 11 March 2015 20:54:09 UTC+8, Bryan Van de ven wrote:

Hi Nicolas,

Thanks for your good questions. First I wanted to mention that I have started work on a new Users Guide which will have much better information and examples around embedding, server apps, etc.

The main advantage of a server app is the two way communication between the python code and app in the browser. In particular, if you want to:

  1. react and respond to changes in plot selections

or

  1. use Bokeh’s widgets and react and respond to changes in those

Then a server app is really the only route to go. If neither of these things is true, then you could do a server app, but it’s not required. If you just want to push data to update a plot, for instance, you can embed it using:

    autoload_server(...)

And then another process (probably your flask or django app) can update the data, which will cause the plot to update.

Regarding the server, you should need one at most. There are ways to run multiple scripts in one server. The easiest it probably just to import the other modules in a new .py file, and use that .py file as your script. If you are using the server in multi-user mode there are config files. Let me know and I can get you more info while I am still working on the docs.

It’s also possible to embed and update using embed.components, but it is much more “coarse grained”. This is going to generate and send the entire plot object every time. There are times when this is perfectly fine. You are correct that if you put several plots into a layout and call embed.components on the entire layout, then you give up control over rendering the plots individually. You could certainly call embed.components on each individual plot (getting a tag for each), but then you are going to have to layout the plots yourself when you render the page, or do some kind of partial page update.

There are probably other questions generated by this but let me stop here and see if what I’ve already said makes sense.

Bryan

I’m wondering in which situation is it better to use applets vs embedding (considering the case of a webapp), and what are the limits of each approach.

After reading the doc (this section of the user_guide & and the examples and these SO questions (one, two)) - there’s still a couple of dark spots for me.

Applets feel overall better (performance, can do dynamic plots with plotting interface), but i have two concerns about them :

  1. Is it advisable to use applets for a multi-page web app ? In that case, should we have one bokeh-server instance per page, with it’s own script ?
  1. It does not seem possible to do per component integration in html - it’s just one single block of js (because we receive only one tag _tag). correct ?

Currently i’m using embedding - it was easy to start as there were many examples.
The drawback of embedding is that it doesn’t seem possible to do dynamic plots using the plotting interface - I haven’t seen any example doing that. Is that correct, or am I missing something ?

Thanks,
Nicolas


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9da63a55-15ff-473b-99de-e52a17838da5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.