本文整理汇总了Python中bokeh.session.Session.register方法的典型用法代码示例。如果您正苦于以下问题:Python Session.register方法的具体用法?Python Session.register怎么用?Python Session.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bokeh.session.Session
的用法示例。
在下文中一共展示了Session.register方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import register [as 别名]
def test_register(self):
#create a dummy config file
config = tempfile.mkdtemp()
#create server
server = Session(name="foo", root_url="http://localhost:5006/",
configdir=config
)
assert server.userapikey == "nokey"
#register a user
server.register("testuser", "fluffy")
assert server.userapikey and server.userapikey != "nokey"
#create a second server configuration
#make sure it loads the proper api key
server2 = Session(name="foo",
configdir=config
)
assert server2.userapikey == server.userapikey
assert server2.root_url == server.root_url
示例2: test_login
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import register [as 别名]
def test_login(self):
#create a server config, register a user
config1 = tempfile.mkdtemp()
server = Session(name="foo", root_url="http://localhost:5006/",
configdir=config1
)
assert server.userapikey == "nokey"
server.register("testuser", "fluffy")
assert server.userapikey and server.userapikey != "nokey"
#create a separate server config, login a user
config2 = tempfile.mkdtemp()
server2 = Session(name="foo", root_url="http://localhost:5006/",
configdir=config2
)
assert server2.userapikey == "nokey"
server2.login("testuser", "fluffy")
#make sure the userapikeys match
assert server2.userapikey == server.userapikey
示例3: prepare_widgets
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import register [as 别名]
def prepare_widgets():
print "initializing..."
# start bokeh-server session
global client
client = Session(root_url='http://0.0.0.0:7010/', load_from_config=False)
try:
client.register(bs_login,bs_password)
except:pass
client.login(bs_login,bs_password)
###CREATE WIDGETS
print "preaparing widgets..."
#hist1: hist with overlay
import analysis.distfit as distfit
import pandas as pd
xname,xmin,xmax,xbins = "invariantMass",0,10,50
bin_separators = np.histogram([],bins=xbins, range=[xmin,xmax])[1]
bin_centers = np.array([0.5*(bin_separators[i]+bin_separators[i+1]) for i in range(len(bin_separators)-1)])
bins = pd.DataFrame({"x":bin_centers})
expo_gap = lambda x,slope: (x>=xmin)*(x<=xmax)*distfit.exponential(x-xmin,slope)/(1.-np.e**(-(xmax-xmin)*slope))
mix_model = distfit.DistributionsMixture(
distributions={'sig': distfit.gauss, 'bck': expo_gap},
weights_ranges={'sig': [1.,10.], 'bck': [1.,10.]},
parameter_ranges={'mean': [xmin ,xmax], 'sigma': [0., xmax-xmin], 'slope': [0, 15.]},
column_ranges={'x': [xmin, xmax]},
sampling_strategy='grid',
)
mix_model.compile(bins,1000) #takes several seconds
hist1_base = WhiskeredHistWidget(xname,xmin,xmax,xbins,es,
fig = figure(plot_width=600, plot_height=600,tools=['wheel_zoom','ywheel_zoom','pan','resize','reset']))
hist1 = MLFitOverlayWidget(hist1_base,mix_model,n_pts=100)
widgets.append(hist1)
#hist2: just hist
hist2 = ClassicHistWidget("muonHits",0,100,30,es,
fig = figure(plot_width=600, plot_height=600,tools=['wheel_zoom','ywheel_zoom','pan','reset']))
widgets.append(hist2)
#hist3: heatmap
hist3 = HeatmapWidget("avgMass",0,35,50,
"muonHits",0,70,50,
es,fig = figure(plot_width=600, plot_height=600),)
widgets.append(hist3)
#hist4: hist with reference
hist4_base = ClassicHistWidget("dskkpi",1920,2020,30,es,
fig = figure(plot_width=600, plot_height=600,tools=['wheel_zoom','ywheel_zoom','pan','reset']))
from scipy.stats import laplace
pdf = laplace(1970,7).pdf
hist4 = ReferenceOverlay(hist4_base,pdf)
widgets.append(hist4)
###end CREATE PLOTS
print "publishing plots..."
#create a dashboard on bokeh_server
output_server(dashboard_name,client)
plots = [ hplot(widget.fig) for widget in widgets ]
global whole_dashboard
whole_dashboard = vplot(hplot(*plots[:2]),hplot(*plots[2:]))
plots.append(whole_dashboard)
for plot in plots:
client.show(plot)
client.publish()
print "creating static links..."
#publish the thing
from bokeh.embed import autoload_server
scripts = [autoload_server(plot,client,public=True) for plot in plots]
print "saving widget scripts..."
#remove previous widgets
for path_to_static in path_to_django_static,path_to_flask_static:
path_to_widgets = os.path.join(path_to_static,dashboard_name)
os.system("rm -rf " + path_to_widgets)
os.mkdir(path_to_widgets)
for i, source_script in enumerate(scripts):
#convert script...
#.........这里部分代码省略.........