···
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
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
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