我有一个Bokeh-python脚本文件,该文件从外部数据库获取数据。基于此,我导入数据以创建数据框并在Python-bokeh中创建堆栈图。
我没有使用javascript或任何其他编程语言的任何经验。
下面是我的散景文件
########## ORACLE CONNECTION ##############
conn=cx_Oracle.connect('rghori/password@10.237.27.178/opt')
fd = open('C:\\py\\programs\\bokeh\\Final\\SQL_Querries\\LTE_Huawei.sql', 'r')
sqlFile = fd.read()
fd.close()
query = sqlFile
df_Oracle=pd.read_sql_query(query,conn)
conn.close()
########### to convert datetime to date and hour ###########
df_Oracle['DATE_TIME'] = pd.to_datetime(df_Oracle['DATE_TIME'])
df_Oracle['date'] = df_Oracle['DATE_TIME'].dt.strftime('%Y-%m-%d')
df_Oracle['hour'] = df_Oracle['DATE_TIME'].dt.strftime('%H:%M')
## again telling python that hour colum now contains contains date time
df_Oracle['hour'] = pd.to_datetime(df_Oracle['hour'])
df_NE = df_Oracle.loc[df_Oracle['REGION'] == "NE"] # Seprate Region
############ Creating plot ########
RRC_SSR_NE = figure(plot_width=900, plot_height=400,
x_axis_type="datetime", title="RRC Setup SSR")
RRC_SSR_NE.title.align = "center"
RRC_SSR_NE.tools = [PanTool(), ResetTool(), WheelZoomTool(), CrosshairTool()]
RRC_SSR_NE.toolbar_location = "above"
RRC_SSR_NE.toolbar.logo = None
week_days1 = df_NE['date'].unique()
source_day1 = {}
week_days = df['date'].unique()
source_day = {}
hover = {}
for days, length, colors in zip(week_days1, range(0, len(week_days1)), itertools.cycle(Category20_20)):
source_day1[str(length)] = ColumnDataSource(
data={
'RRC_SSR_NE': df_NE[df_NE["date"] == days]["RRC_SR"],
'hour': df_NE[df_NE["date"] == days]["hour"]
})
RRC_SSR_NE.line(x="hour", y="RRC_SSR_NE",
color=colors, line_width=3, source=source_day1[str(length)], legend=days)
hover = HoverTool(tooltips=[("RRC SSR:", "@RRC_SSR_NE{1.11}")])
RRC_SSR_NE.add_tools(hover)
RRC_SSR_NE.legend.background_fill_alpha = 0
RRC_SSR_NE.legend.click_policy = "hide"
RRC_SSR_NE.legend.location = "top_left"
LTE_Grid_NE = gridplot([RRC_SSR_NE, RRC_Fail_NE])
# GRID
js_grid_LTE_NE, div_grid_LTE_NE = components(LTE_Grid_NE)
cdn_js = CDN.js_files[0]
cdn_css = CDN.css_files[0]
外部数据库每小时更新一次,以下是使用FLASK调用我的bokeh应用程序。
下面是我的烧瓶文件。
from flask import Flask, render_template, cli, url_for
from NE_LTE import js_grid_LTE_NE, div_grid_LTE_NE, cdn_js, cdn_css
@app.route('/NE_LTE')
def NE_LTE():
return render_template("NE_LTE.html", js_grid_LTE_NE=js_grid_LTE_NE, div_grid_LTE_NE=div_grid_LTE_NE, cdn_js=cdn_js, cdn_css=cdn_css, df=df)
执行烧瓶应用程序后,它将加载数据并显示图,但刷新后不会更新。我需要退出该应用程序,然后再次重新执行FLASK应用程序。
当数据库中的数据更新时,请提供一些有关如何更新视图的建议,而我不必为了获取数据中的更改而重启服务器。
感谢所有帮助。
最好的问候