I have bokeh application with around 6 tabs and 3-4 interactive plots under each tab. These plots have a lot of datapoints and take time to plot. Loading all plots in one shot is fairly slow, so I want to use flask to draw one tab at a time:
Now looking at the returned html on the browser, I see that the script is downloaded and expanded for each of the tabs, but is not executed (so doesn’t expand to actual chart). This is expected because innerHTML writes it as a string. However appendChild itself fails because the return of render_template_string is a string and not a JS object.
I think your only option is to eval the script body in openvtab. So you will need to strip off the outer HTML markup (or else re-implement the parts of server_session that create the script source code).
@codeyman That would definitely cause a problem. This is definitely not intended / standard usage, so I am not too surprised that there are issues. I’m not sure what guidance I can offer here, it seems likely that this would need to be properly developed as a supported use case, which might mean new development is needed. A github issue would be the next step to start that discussion. Just a heads up: what would help move the needle, more than anything, is a fleshed out proposal, i.e. a complete example script of what you’d like to be able to do, that would serve as the benchmark for success (your example script works when the work is complete).
To rephrase the problem in a different way. Let’s say I’ve already loaded all my plots into curdoc(). Is there a way to just get any added plot later via bokeh server?
p1 = figure(..., name='plot1')
p2 = figure(..., name='plot2')
curdoc().add_root(p1)
curdoc().add_root(p2)
@app.route('/')
def index():
with pull_session(url="..") as dsession:
#stash the sessionid here
app.route('/tabs/<string:tabname>')
def renderTab(tabname):
#Assuming there is some API like this that just gives me the figure for a particular session
#tabname can be plot1 or plot2 here.
plotscript = server_session(session_id=session.id, url='...', plotname=tabname)
That I’m actual looking for is something like Bokeh.embed.embed_items that can serve live graphs from the session.
@codeyman The above code snippet above definitely won’t work for a fundamental reason. The app code is only executed once per session, when the session is created. So HTTP arguments e.g plotname for a session that already exists, will never get used (because the app code that might switch on that value has already run, and won’t run again for this session).
Edit: and I had to double check but yes, there is not any parameters to server_session for passing HTTP arguments (if there were, I’d argue that would be a mistake to fix).
So then an off-the-cuff idea might be to afford a way to specify a “session embed” callback that can be run whenever a session is embedded in order to customize the existing session further. That seems like it would satisfy your needs, but it would require new developement, and also discussion (in case there are good reasons not to add that, or other better ways to accomplish things)