简体   繁体   中英

bokeh plot empty when rendering Flask template

I am trying to embed a bokeh plot in a webpage served by a simple Flask app, using the embed.autoload_server function that I picked up from looking over the bokeh embed examples on github. Everything seems to be working as expected on the python side of things, but the page renders without any data (even though the data is within the JS plot object). I do see the 5 bokeh plot manipulation buttons but I do not see the actual plot. After turning on the JS console I see that the i variable is being returned as undefined in the following statement (line 23512, bokeh.js):

i = this.get('dimension');

As a result, ranges[i] is also undefined, which is the error I'm getting in the console.

I can navigate the browser to the actual plot json and I see all the data as expected there, which is why I turned to the JS console to troubleshoot.

Any ideas would be very appreciated, my JS is pretty rusty at the moment. Is there a relationship between the attributes of the python "plot" objects and the JS "plot" objects? It seems like this is just an issue of my front end object missing the "dimension" attribute.

In response to the question, here is the code, it is pretty much lifted directly from the candlestick example code, but that was from a pull from several weeks ago, so it very well could be dated. I pulled again since and didn't revisit this code since there were no issues creating the plot data.

def candlestick():
    store = pd.HDFStore('../data/dt_metastock.h5')

    keys = [key for key in store.keys() if 'daily' in key]
    df = store[keys[0]][:800]
    #df['date'] = pd.to_datetime(df['date'])

    mids = (df.open + df.close)/2
    spans = abs(df.close-df.open)

    inc = df.close > df.open
    dec = df.open > df.close
    w = 12*60*60*1000 # half day in ms

    output_server("candlestick")
    figure(tools="pan,wheel_zoom,box_zoom,reset,previewsave",
           plot_width=1000, name="candlestick")

    hold()

    segment(df.idx, df.high, df.idx, df.low, color='black')
    w = .5
    rect(df.idx[inc].values, mids[inc], w, spans[inc], fill_color="#D5E1DD", line_color="black")
    rect(df.idx[dec].values, mids[dec], w, spans[dec], fill_color="#F2583E", line_color="black")

    curplot().title = keys[0]
    xaxis().major_label_orientation = pi/4
    grid().grid_line_alpha=0.3
    tag = embed.autoload_server(curplot(), cursession())
    return tag

Can you post the code of your plot? Recently, we have merged a new layout system and it seems to me that you are probably using and old way to set up the axes in your plot...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM