This makes sense. It may make sense for me to perform database queries or other expensive data analysis operations in the on_server_loaded lifecycle hook then. Is there an easy way for me to pass data-variables from the lifecycle to the main application?
Thanks,
Reuben
···
On Wednesday, August 10, 2016 at 10:45:28 AM UTC-4, Bryan Van de ven wrote:
Reuben,
This is exactly the way the bokeh server functions. The “app code” is re-run every single session, to create a new, unique set of new bokeh models to support that session. If the app code is doing something expensive, but that really only needs to be run once, then you can refer to some of the links I sent earlier about lifecycle hooks, etc. to perform the expensive work once, on initial server startup, and then share the results between sessions without re-computing. However, this kind of sharing is only suitable for non-Bokeh models, i.e. “plain data”. Every session needs to create new plots, tools, column data sources, etc. The alternative would be “google doc” type sharing where one person moves a slider and everyone else has their page update too. The spectrogram example I also linked is an example of this.
If the work is expensive, and needs to happen every session (because the computations or whatever are different every time), there’s probably not much to do. You could up the value of --num-threads, tho I don’t think that would really help in such a situation. I would like to add some messages to signal “busy / working” during long running callbacks, so that some visual cue can be given when blocking work is happening, but those do not exist yet.
Thanks,
Bryan
On Aug 10, 2016, at 9:26 AM, Reuben Jacobs [email protected] wrote:
Hi Bryan,
So, from testing I have determined that this web app, when run with flask, is computing my bokeh charts on initial startup and simply serving them to me when I reload the page. However, with bokeh server it appears to be recomputing the charts every time I reload the page. Below you can see how I am starting the server with flask and then how I am doing it with bokeh server.
FLASK:
from future import print_function
import flask
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.resources import INLINE
from bokeh.util.string import encode_utf8
from bokeh.models.widgets import Panel, Tabs
from bokeh.io import output_file, show
import Maestro
from Maestro import getAllPlots
app = flask.Flask(name)
vioAll, vioClin, vioCoh, barAll, barClin, barCoh = getAllPlots()
tabvioAll = Panel(child=vioAll, title=“Violin”)
tabBarAll = Panel(child=barAll, title=“Bar”)
tabvioClin = Panel(child=vioClin, title=“Violin”)
tabBarClin = Panel(child=barClin, title=“Bar”)
tabvioCoh = Panel(child=vioCoh, title=“Violin”)
tabBarCoh = Panel(child=barCoh, title=“Bar”)
tabsAll = Tabs(tabs=[ tabvioAll, tabBarAll ])
tabsClin = Tabs(tabs=[ tabvioClin, tabBarClin ])
tabsCoh = Tabs(tabs=[ tabvioCoh, tabBarCoh ])
vioAllScript, vioAlldiv = components(vioAll, tabsAll, INLINE)
vioClinScript, vioClindiv = components(vioClin, tabsClin, INLINE)
vioCohScript, vioCohdiv = components(vioCoh, tabsCoh, INLINE)
barAllScript, barAlldiv = components(barAll, INLINE)
barClinScript, barClindiv = components(barClin, INLINE)
barCohScript, barCohdiv = components(barCoh, INLINE)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
@app.route(“/”)
def Maestro():
print("Maestro")
# Configure resources to include BokehJS inline in the document.
# For more details see:
# [http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed](http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed)
# For more details see:
# [http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components](http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components)
html = flask.render_template(
'embed.html',
vioAll_script=vioAllScript,
vioClin_script=vioClinScript,
vioCoh_script=vioCohScript,
vioAll_div=vioAlldiv,
vioClin_div=vioClindiv,
vioCoh_div=vioCohdiv,
barAll_script=barAllScript,
barClin_script=barClinScript,
barCoh_script=barCohScript,
barAll_div=barAlldiv,
barClin_div=barClindiv,
barCoh_div=barCohdiv,
js_resources=js_resources,
css_resources=css_resources,
)
return encode_utf8(html)
if name == “main”:
print(__doc__)
app.run(debug=True, host="0.0.0.0",use_reloader=False)
BOKEH SERVER:
from future import print_function
from bokeh.io import output_file, show, curdoc
from bokeh.layouts import column
from bokeh.models.widgets import Panel, Tabs
from Maestro import getAllPlots
import Maestro
vioAll, vioClin, vioCoh, barAll, barClin, barCoh = getAllPlots()
tabvioAll = Panel(child=vioAll, title=“Violin”)
tabBarAll = Panel(child=barAll, title=“Bar”)
tabvioClin = Panel(child=vioClin, title=“Violin”)
tabBarClin = Panel(child=barClin, title=“Bar”)
tabvioCoh = Panel(child=vioCoh, title=“Violin”)
tabBarCoh = Panel(child=barCoh, title=“Bar”)
curdoc().add_root(column(vioAll))
The function getAllPlots() is the one used to compute the charts themselves. Any idea why this is happening, or is that the nature of these two servers?
On Tuesday, August 9, 2016 at 5:16:29 PM UTC-4, Bryan Van de ven wrote:
At this point, I would suggest some “printf” style debugging. Basically, instrument all these functions to print out when they run, and ideally to also print out how long they take to run (call time.time() at the beginning and end and print the diff)
Bryan
On Aug 9, 2016, at 3:56 PM, Reuben Jacobs [email protected] wrote:
Bryan,
I can provide some code for you just not the queries themselves.
Here is the method called to generate the plots
def getAllPlots():
Cool, Riker = removeChargebacksAndCollaborationData(CoolQuery, RikerQuery, CoolCols, RikerCols)
maestro = binCoolPathDataByWeek(Cool, vioCols)
maestro[“Total Turnaround Time (Days)”][maestro[“Total Turnaround Time (Days)”] > 100] = 101
stats, aggStats = Metronome(maestro, maestroCols)
violinDataAll = pd.merge(maestro, stats, how=‘left’, on=“Week of”, sort=False, suffixes=(‘_x’, ‘_y’), copy=True, indicator=False)
violinDataAll = violinDataAll.sort_values(by = “Signedout Datetime”)
violinDataClin = violinDataAll[violinDataAll[“Case Type”] == “Clinical”]
violinDataCoh = violinDataAll[violinDataAll[“Case Type”] == “Profile”]
barTender, barTab, debt, barMaster = barRescue(Cool, Riker, maestro, barCols)
barMasterClin = barMaster[barMaster[“caseType”] == “Clinical”]
barMasterCoh = barMaster[barMaster[“caseType”] == “Profile”]
vioAll = createViolinPlot(violinDataAll, “All”)
vioClin = createViolinPlot(violinDataClin, “Clinical”)
vioCoh = createViolinPlot(violinDataCoh, “Cohort”)
barAll = createBarGraph(barMaster, “All”)
barClin = createBarGraph(barMasterClin, “Clinical”)
barCoh = createBarGraph(barMasterCoh, “Cohort”)
return vioAll, vioClin, vioCoh, barAll, barClin, barCohAnd then moving along the calls
def createViolinPlot(df, caseType):
sns.set_style(“whitegrid”)ax = sns.violinplot(x="Week of", y="Total Turnaround Time (Days)", data=df, palette="muted", split=False, scale="count", inner="box", bw=0.1) ax.set_title("Total Turnaround Time for {} Cases Since July 1, 2015".format(caseType)) #labels = ax.get_xticklabels() v = mpl.to_bokeh() v.plot_width = 1200 v.plot_height = 900 v.xaxis.major_label_orientation = pi/4 v.axis.major_label_standoff = 30 #def callback(source=df, window=None): #beginSlider = Slider(start=0, end=10, value=1, step=.1, title="Start Date") #endSlider = Slider(start=0, end=10, value=1, step=.1, title="End Date") return v
On Tuesday, August 9, 2016 at 4:48:48 PM UTC-4, Bryan Van de ven wrote:
OK it sounds like the app is duplicating effort in some accumulative way. Unfortunately without seeing real code I can’t speculate much further.Bryan
On Aug 9, 2016, at 3:11 PM, Reuben Jacobs [email protected] wrote:
Not generating colors anywhere. The page loads much faster with Flask (but serves MB vs KB with bokeh server) without any console errors just checked. I’m not so sure the RGB is my issue.
On Tuesday, August 9, 2016 at 3:58:51 PM UTC-4, Bryan Van de ven wrote:
OK I think there may be a bug wrt to color values specified as “rgb(…)”. That seems vaguely familiar. So the next question is then: are you generating color values that way somewhere? If not they must be coming out of the mpl compat layer somewhere.Bryan
On Aug 9, 2016, at 2:56 PM, Reuben Jacobs [email protected] wrote:
Bryan,
The database calls definitely do not hang indefinitely. I was using Flask to run this on server earlier today and there were no issues with reloading the page. In addition, the page finishes loading the first visit
On the first load of the page (where the plots) load fine there are a lot of JS errors that look the same like
bokeh.min.js:67 Bokeh: Error handling message: Error: attempted to retrieve property array for nonexistent field ‘rgb(255, 255, 255)’, [object MessageEvent
A bunch of others for different RGB values.On the first , working, page visit the bokeh server console log states
2016-08-09 15:49:32,653 200 GET /Tenacity (::1) 72721.00ms
2016-08-09 15:49:33,163 WebSocket connection opened
2016-08-09 15:49:33,163 ServerConnection created
However, if I try to refresh the page there is no mention of a request in the server log console and nothing mentioned in the JS console. Any refreshes or page visits after the initial load remain pending in the JS console network tab. It seems to sit at “waiting for localhost” after the initial load if I want to refresh or visit the page again.Reuben
On Tuesday, August 9, 2016 at 3:41:28 PM UTC-4, Bryan Van de ven wrote:
I just opened 10 copies of examples/app/sliders.py without issue. It’s going to be difficult to diagnose this without code to run, or more information. Is there any output in the console log from the server? What about in the broswer JavaScript console?Thanks,
Bryan
On Aug 9, 2016, at 2:37 PM, Reuben Jacobs [email protected] wrote:
Hi Bryan,
My code to build the plots themselves is complex and uses company database queries so I can not provide that. However, they do open fine on the first opened browser and below is the code that I am using as the wrapper.
from future import print_function
from bokeh.embed import components
from bokeh.io import output_file, show, curdoc
from bokeh.layouts import column
from bokeh.models.widgets import Panel, Tabs
from bokeh.plotting import figure
from bokeh.resources import INLINE
from bokeh.util.string import encode_utf8from Maestro import getAllPlots
import MaestrovioAll, vioClin, vioCoh, barAll, barClin, barCoh = getAllPlots() #this is my project method that builds violin plots
tabvioAll = Panel(child=vioAll, title=“Violin”)
tabBarAll = Panel(child=barAll, title=“Bar”)tabvioClin = Panel(child=vioClin, title=“Violin”)
tabBarClin = Panel(child=barClin, title=“Bar”)tabvioCoh = Panel(child=vioCoh, title=“Violin”)
tabBarCoh = Panel(child=barCoh, title=“Bar”)tabsAll = Tabs(tabs=[ tabvioAll, tabBarAll ])
tabsClin = Tabs(tabs=[ tabvioClin, tabBarClin ])
tabsCoh = Tabs(tabs=[ tabvioCoh, tabBarCoh ])curdoc().add_root(column(vioAll, vioClin, vioCoh, barAll, barClin, barCoh))
In addition version information:
Python27
Bokeh 0.12.1On Tuesday, August 9, 2016 at 3:30:38 PM UTC-4, Bryan Van de ven wrote:
Can you provide runnable example code to reproduce the problem? It’s hard to speculate without code to run. Additionally version and platform information.Thanks,
Bryan
On Aug 9, 2016, at 2:29 PM, Reuben Jacobs [email protected] wrote:
Hi all,
I just created a Bokeh Server, but I seem to only be able to connect to it once. More specifically,
In my main.py I have
curdoc().add_root(column(vioAll, vioClin, vioCoh, barAll, barClin, barCoh))
All of these variables are various plots.Next, I run my server with
bokeh --show main.py
The server takes a long time to load but that is to be expected with the number of calculations I am doing. If I wait for the browser to load (the one that was started up by the --show) it will load. However, if I close that tab and navigate to the correct localhost URL after the server has started, the page will not load.Does anyone know what might be happening here?
Thank you,
Reuben–
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/2c951418-02e0-48bc-8d4d-0ebe5c1ad4ca%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.–
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/8e006c64-128f-4c3e-bf3d-20b267ce0d22%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.–
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/d46435e6-8018-4de8-b4e0-4ff250e067cd%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.–
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/5112b5cd-7a7b-4067-afe3-7b4f166b33e5%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.–
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/ae5f0417-4aae-4b00-b149-97a9dfd6eba8%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.–
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/cb0a23fa-5e68-4313-b141-524e108d8e13%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.