Confused about how to go from server document name to JS embed snippet

Hey all.
So, I’ve got some back-end code that generates a plot (chart actually) and stores it on the bokeh-server with an appropriate document name (take several hours to generate the data).

(just using something like TimeSeries(df, title=label, server=‘nicegraph’).show() )

Now, I can happily view the plot by accessing localhost:5006.

So, from another web-app, how can I get a handle on that to pass to autoload_server(plot,session) in order to embed the appropriate JS snippet that will display it in my web page?

I can do:

session = Session(name=‘http://host:5006’)

doc_id = session.find_doc(‘nicegraph’)

session.use_doc(doc_id)

but there I’m stuck as autoload_server takes a plot & a session.

Help appreciated.

Thanks,

-David

So, are you asking how to get the plot object? Because you already answered here: https://github.com/bokeh/bokeh/issues/829#issuecomment-61876977 :wink:

About the session, we don’t currently expose the session object in charts, this is something we need to fix, can you open an issue for that?

Thanks.

Damian

···

On Tue, Nov 11, 2014 at 2:09 PM, David Jung [email protected] wrote:

Hey all.
So, I’ve got some back-end code that generates a plot (chart actually) and stores it on the bokeh-server with an appropriate document name (take several hours to generate the data).

(just using something like TimeSeries(df, title=label, server=‘nicegraph’).show() )

Now, I can happily view the plot by accessing localhost:5006.

So, from another web-app, how can I get a handle on that to pass to autoload_server(plot,session) in order to embed the appropriate JS snippet that will display it in my web page?

I can do:

session = Session(name=‘http://host:5006’)

doc_id = session.find_doc(‘nicegraph’)

session.use_doc(doc_id)

but there I’m stuck as autoload_server takes a plot & a session.

Help appreciated.

Thanks,

-David

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/4b8e03d3-7736-486f-b53f-9c4e225c153d%40continuum.io.

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

So, are you asking how to get the plot object?

From a document id or name string, yes.

Because you already answered here:
Embedding Chart objects in a webpage · Issue #829 · bokeh/bokeh · GitHub :wink:

No, unrelated. That was about how to expose the plot object from a chart
object in-process.
In that case I already had a chart object and just needed to extract the
plot object. Now, I'm writing an independent web-app that has nothing to
do with generating the charts or plots - it just needs to lookup the
plot/chart document by name from the bokeh-server. As the title says, I
don't understand how to go from nothing but a string name for a document on
the bokeh-server to a script snippet I can insert into a HTTP response and
have that (in conjunction with the Bokeh JS lib) actually fetch and display
the plot from the server.

About the session, we don't currently expose the session object in charts,
this is something we need to fix, can you open an issue for that?
Thanks.

There is already an issue open for that, though it won't help in this
case. If we forget about charts and just consider plots, the issue is the
same - how can I get from a string name of a document containing a plot
that has been previously stored in the bokeh-server by an independent
process, to a JS snippet to embed into a HTTP page such that it'll display
inline?
The couple lines of code I pasted maps from the document name to the
document UUID (by calling the bokeh-server API through the client code),
but from there I don't know how to generate something like:

<script
    src="http://localhost:5006/bokeh/autoload.js/7b6e5722-b7e1-4b9e-b8d9-84e1059f7dea&quot;
    id="7b6e5722-b7e1-4b9e-b8d9-84e1059f7dea"
    async="true"
    data-bokeh-data="server"
    data-bokeh-modelid="da023ae3-b88b-45b5-8fc1-f45c53f09fa2"
    data-bokeh-modeltype="Plot"
    data-bokeh-root-url="http://localhost:5006/&quot;
    data-bokeh-docid="db499b59-c06e-4415-a482-af9802512ede"
    data-bokeh-docapikey="45959c87-3120-4ce5-a1ec-ca0720023951"
    data-bokeh-conn-string="ws://localhost:5006/bokeh/sub"

</script>

(I can't even manually generate that as I don't know what the modelid is
nor what the UUID suffix on the URL represents)

Thanks,
-David

···

On Tue, Nov 11, 2014 at 1:01 PM, Damian Avila <[email protected]> wrote:

On Tue, Nov 11, 2014 at 2:09 PM, David Jung <[email protected]> > wrote:

Hey all.
So, I've got some back-end code that generates a plot (chart actually)
and stores it on the bokeh-server with an appropriate document name (take
several hours to generate the data).
(just using something like TimeSeries(df, title=label,
server='nicegraph').show() )

Now, I can happily view the plot by accessing localhost:5006.

So, from another web-app, how can I get a handle on that to pass to
autoload_server(plot,session) in order to embed the appropriate JS
snippet that will display it in my web page?

I can do:
session = Session(name='http://host:5006')
doc_id = session.find_doc('nicegraph')
session.use_doc(doc_id)

but there I'm stuck as autoload_server takes a plot & a session.

Help appreciated.
Thanks,
-David

--
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/4b8e03d3-7736-486f-b53f-9c4e225c153d%40continuum.io
<https://groups.google.com/a/continuum.io/d/msgid/bokeh/4b8e03d3-7736-486f-b53f-9c4e225c153d%40continuum.io?utm_medium=email&utm_source=footer&gt;
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout
.

--
You received this message because you are subscribed to a topic in the
Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit
https://groups.google.com/a/continuum.io/d/topic/bokeh/70xxvebF86o/unsubscribe
.
To unsubscribe from this group and all its topics, 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/CAM9Ly3EgDMQn0f0z1qcU9%3DTEZCJk%2BpcgTQ5_hH-vfBBk8X3ZqQ%40mail.gmail.com
<https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAM9Ly3EgDMQn0f0z1qcU9%3DTEZCJk%2BpcgTQ5_hH-vfBBk8X3ZqQ%40mail.gmail.com?utm_medium=email&utm_source=footer&gt;
.

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

David,

···

On Tue, Nov 11, 2014 at 3:14 PM, David Jung [email protected] wrote:

Unrelated now that I understand better your question… but it is not totally unrelated :wink:

I have to correct myself here, we actually expose the session object… I forgot about that…

OK, let’s try this:

from bokeh.plotting import autoload

from bokeh.session import Session

from bokeh.document import Document

def load_plot(name):

s = Session()

s.use_doc(name)

d = Document()

s.load_document(d)

return autoload_server(d.context, s)

snippet = load_plot(‘my_ts_plot’)

def write(fname, snippet):

with open(fname, “w+”) as f:

f.write(“\n”)

f.write(“\n”)

f.write(snippet)

f.write(“\n”)

f.write(“\n”)

f.write(“\n”)

write(“my_embedded.html”, snippet)

So, with d.context you have the reference you are asking for…

Hope it helps!

Damian

On Tue, Nov 11, 2014 at 1:01 PM, Damian Avila [email protected] wrote:

So, are you asking how to get the plot object?

From a document id or name string, yes.

Because you already answered here: https://github.com/bokeh/bokeh/issues/829#issuecomment-61876977 :wink:

No, unrelated. That was about how to expose the plot object from a chart object in-process.

In that case I already had a chart object and just needed to extract the plot object. Now, I’m writing an independent web-app that has nothing to do with generating the charts or plots - it just needs to lookup the plot/chart document by name from the bokeh-server. As the title says, I don’t understand how to go from nothing but a string name for a document on the bokeh-server to a script snippet I can insert into a HTTP response and have that (in conjunction with the Bokeh JS lib) actually fetch and display the plot from the server.

About the session, we don’t currently expose the session object in charts, this is something we need to fix, can you open an issue for that?

Thanks.

There is already an issue open for that, though it won’t help in this case. If we forget about charts and just consider plots, the issue is the same - how can I get from a string name of a document containing a plot that has been previously stored in the bokeh-server by an independent process, to a JS snippet to embed into a HTTP page such that it’ll display inline?

The couple lines of code I pasted maps from the document name to the document UUID (by calling the bokeh-server API through the client code), but from there I don’t know how to generate something like:

    <script
src="[http://localhost:5006/bokeh/autoload.js/7b6e5722-b7e1-4b9e-b8d9-84e1059f7dea](http://localhost:5006/bokeh/autoload.js/7b6e5722-b7e1-4b9e-b8d9-84e1059f7dea)    "
id="7b6e5722-b7e1-4b9e-b8d9-84e1059f7dea"
async="true"
data-bokeh-data="server"
data-bokeh-modelid="da023ae3-b88b-45b5-8fc1-f45c53f09fa2"
data-bokeh-modeltype="Plot"
data-bokeh-root-url="[http://localhost:5006/](http://localhost:5006/)    "
data-bokeh-docid="db499b59-c06e-4415-a482-af9802512ede"
data-bokeh-docapikey="45959c87-3120-4ce5-a1ec-ca0720023951"
data-bokeh-conn-string="ws://localhost:5006/bokeh/sub"
></script>

(I can’t even manually generate that as I don’t know what the modelid is nor what the UUID suffix on the URL represents)

Thanks,

-David

Indeed it does - works like a charm, thankyou!

-David

···

On Tuesday, November 11, 2014 3:17:11 PM UTC-5, Damian Avila wrote:

OK, let’s try this:

[…]

So, with d.context you have the reference you are asking for…

Hope it helps!