Dear Friends,
I had a Bokeh-python script file that fetches the data from an external database. Base on that I import the data to create a data-frame and create a stack plot in Python-Bokeh.
Below is my Bokeh File
########## ORACLE CONNECTION ##############
conn=cx_Oracle.connect('rghori/[email protected]/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 Bokeh 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]
1.
the external database is updated hourly and below is the calling my Bokeh app using FLASK.
Below is the code from my flask File.
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 = Flask(name)
def home():
return render_template(“main.html”)
@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)
Once I execute the flask app it loads the data and the plot is displayed but it does not get updated by refreshing. I need to exit the app and re-execute the FLASK app again.
please need some suggestions as to how to update the view when data gets updated in my database and I won’t have to restart the server just to pick up changes in my data.
Thanks for all the help.
Best Regards