我试图在Bokeh中提供实时更新的图形,但是当我在代码中更新test.txt文件时,数组会显示新值,但除非刷新浏览器,否则屏幕上的图形不会更新。< / p>
def update():
new_data = pd.read_csv(('/tmp/app/time_series/data/test.txt'))
source.stream(dict(DATE=new_data["DATE"],
RH=new_data["RH"], WS=new_data["WS"], P=new_data["P"],
WD=new_data["WD"], WSMAX=new_data["WSMAX"], T=new_data["T"]), 5)
print("It's working... now")
return
然后在代码末尾,有这些行称为更新。我得到了打印语句,因此我知道它每5秒工作一次,但是屏幕上的图形不会更新。有什么想法吗?
curdoc().add_root(p1)
curdoc().add_periodic_callback(update, 5000)
curdoc().title = "METAR DATA"
编辑: 以下是创建源代码然后传递给更新的相关事件行:
df = pd.read_csv(('/tmp/app/time_series/data/test.txt'))
grouped = df.groupby('DATE').sum()
source = ColumnDataSource(grouped)
这是我的示例test.txt文件的样子
,DATE,P,RH,T,WD,WS,WSMAX
2019-12-13 00:00:00,2019-12-13 00:00:00,000.0,89.4541,275.557,000.0,4.25811,4.61343
2019-12-13 00:1:00,2019-12-13 00:1:00,000.0,96.6287,275.048,000.0,5.22523,5.80503
2019-12-13 00:2:00,2019-12-13 00:2:00,000.0,97.0209,275.448,000.0,6.00924,5.903
2019-12-13 00:3:00,2019-12-13 00:3:00,000.0,97,276.248,000.0,6.27924,5.907
2019-12-13 00:4:00,2019-12-13 00:4:00,000.0,97,277.062,000.0,6.45150,6
2019-12-13 00:5:00,2019-12-13 00:5:00,000.0,96.179,278.121,000.0,5.95553,5.03016
2019-12-13 00:6:00,2019-12-13 00:6:00,000.0,97.159,278.912,000.0,7.04365,6.70554
2019-12-13 00:7:00,2019-12-13 00:7:00,000.0,97.1566,279.567,000.0,7.60248,7.24801
2019-12-13 00:8:00,2019-12-13 00:8:00,000.0,98.0921,279.99,000.0,8.43979,8.34936
2019-12-13 00:9:00,2019-12-13 00:9:00,000.0,98,279.671,000.0,8.02470,8.92599
2019-12-13 00:10:00,2019-12-13 00:10:00,000.0,98,279.942,000.0,7.25503,7.04352
2019-12-13 00:11:00,2019-12-13 00:11:00,000.0,98,280.217,000.0,7.87708,8.04931
2019-12-13 00:12:00,2019-12-13 00:12:00,000.0,98,281.464,000.0,8.63792,9.2582
2019-12-13 00:13:00,2019-12-13 00:13:00,000.0,98.0675,282.664,000.0,9.32942,7.64972
2019-12-13 00:14:00,2019-12-13 00:14:00,000.0,98.485,282.105,000.0,10.01741,11.7325
2019-12-13 00:15:00,2019-12-13 00:15:00,000.0,98.3423,281.329,000.0,8.78744,9.95701
2019-12-13 00:16:00,2019-12-13 00:16:00,000.0,98.113,280.847,000.0,5.968683,2.91149
2019-12-13 00:17:00,2019-12-13 00:17:00,000.0,97.6763,280.835,000.0,2.773576,0.827212
2019-12-13 00:18:00,2019-12-13 00:18:00,000.0,98.3592,280.932,000.0,2.66205,1.22099
2019-12-13 00:19:00,2019-12-13 00:19:00,000.0,97.6503,280.791,000.0,3.79568,2.30775
2019-12-13 00:20:00,2019-12-13 00:20:00,000.0,98.0024,280.402,000.0,4.94331,3.6216
2019-12-13 00:21:00,2019-12-13 00:21:00,000.0,98.0083,280.029,000.0,5.47667,5.80305
2019-12-13 00:22:00,2019-12-13 00:22:00,000.0,98.0166,279.637,000.0,5.40177,6.5088
2019-12-13 00:23:00,2019-12-13 00:23:00,000.0,98.004,279.448,000.0,5.24201,6.12557
2019-12-13 00:24:00,2019-12-13 00:24:00,000.0,98.0449,279.421,000.0,8.48943,13.1107