- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
注意:这个问题涉及“第一代” Bokeh 服务器,该服务器已被弃用和删除了几年。此问题或其答案中的任何内容都与任何版本的 Bokeh >= 0.11
无关有关使用受支持的现代 Bokeh 服务器的详细信息,请参阅 Running a Bokeh Server用户指南的章节。
我正在努力理解 Bokeh对于我正在构建的交互式应用程序。我在看Bokeh examples ,并且我看到大多数示例都是在全局命名空间中编写的,但是“app”子目录中的示例以很好的面向对象风格编写,其中主类继承自像 HBox 这样的 Property 类。
这将是一堆问题,因为我认为这种 Bokeh 编程方式没有得到很好的记录。我遇到的第一件事是情节没有绘制,除非我包含 extra_generated_classes
。
extra_generated_classes 有什么作用?
其次,看起来事件循环 setup_events
在启动时在 create
之前调用,随后每次情节触发事件时调用。
为什么 setup_events 每次触发事件时都需要注册回调?为什么在第一次尝试注册它们之前不等待创建完成?
我不确定的最后一件事是如何在此处强制重绘字形。 slider 演示适用于我,我尝试做基本相同的事情,除了使用散点图而不是线。
我在 update_data
的最后设置了一个 pdb 跟踪,我可以保证 self.source
匹配 self.plot.renderers[-1 ].data_source
并且从一开始就对它们进行了调整。然而,self.plot
本身并没有改变。
什么是面向对象的方法相当于调用 store_objects 来更新绘图?
我对第三个特别困惑,因为它看起来不像 sliders_app 示例需要这样的东西。为了澄清起见,我正在尝试制作可变数量的小部件/ slider ,所以这就是我的代码的样子:
类属性:
extra_generated_classes = [['ScatterBias', 'ScatterBias', 'HBox']]
maxval = 100.0
inputs = Instance(bkw.VBoxForm)
outputs = Instance(bkw.VBoxForm)
plots = Dict(String, Instance(Plot))
source = Instance(ColumnDataSource)
cols = Dict(String, String)
widgets = Dict(String, Instance(bkw.Slider))
# unmodified source
df0 = Instance(ColumnDataSource)
初始化方法
@classmethod
def create(cls):
obj = cls()
##############################
## load DataFrame
##############################
df = pd.read_csv('data/crime2013_tagged_clean.csv', index_col='full_name')
obj.cols = {'x': 'Robbery',
'y': 'Violent crime total',
'pop': 'Population'
}
cols = obj.cols
# only keep interested values
df2= df.ix[:, cols.values()]
# drop empty rows
df2.dropna(axis=0, inplace=True)
df0 = df2.copy()
df0.reset_index(inplace=True)
# keep copy of original data
obj.source = ColumnDataSource(df2)
obj.df0 = ColumnDataSource(df0)
##############################
## draw scatterplot
##############################
obj.plots = {
'robbery': scatter(x=cols['x'],
y=cols['y'],
source=obj.source,
x_axis_label=cols['x'],
y_axis_label=cols['y']),
'pop': scatter(x=cols['pop'],
y=cols['y'],
source=obj.source,
x_axis_label=cols['pop'],
y_axis_label=cols['y'],
title='%s by %s, Adjusted by by %s'%(cols['y'],
cols['pop'], cols['pop'])),
}
obj.update_data()
##############################
## draw inputs
##############################
# bokeh.plotting.scatter
## TODO: refactor so that any number of control variables are created
# automatically. This involves subsuming c['pop'] into c['ctrls'], which
# would be a dictionary mapping column names to their widget titles
pop_slider = obj.make_widget(bkw.Slider, dict(
start=-obj.maxval,
end=obj.maxval,
value=0,
step=1,
title='Population'),
cols['pop'])
##############################
## make layout
##############################
obj.inputs = bkw.VBoxForm(
children=[pop_slider]
)
obj.outputs = bkw.VBoxForm(
children=[obj.plots['robbery']]
)
obj.children.append(obj.inputs)
obj.children.append(obj.outputs)
return obj
update_data
def update_data(self):
"""Update y by the amount designated by each slider"""
logging.debug('update_data')
c = self.cols
## TODO:: make this check for bad input; especially with text boxes
betas = {
varname: getattr(widget, 'value')/self.maxval
for varname, widget in self.widgets.iteritems()
}
df0 = pd.DataFrame(self.df0.data)
adj_y = []
for ix, row in df0.iterrows():
## perform calculations and generate new y's
adj_y.append(self.debias(row))
self.source.data[c['y']] = adj_y
assert len(adj_y) == len(self.source.data[c['x']])
logging.debug('self.source["y"] now contains debiased data')
import pdb; pdb.set_trace()
请注意,我确信事件处理程序已正确设置和触发。我只是不知道如何使更改后的源数据反射(reflect)在散点图中。
最佳答案
我正在寻找相同的答案(缺乏文档使其变得困难)。
回答问题 #1,“extra_generated_classes”的用途是什么:
tl;dr extra_generated_classes 定义了用于模板生成js/html代码的modulename、classname和parentname,并扩展了传递给app类的父类(示例中通常为HBox或VBox) .
更长的答案。查看 bokeh/server/utils/plugins.py 中的源代码,这是在使用 --script 命令行参数传递给 bokeh-server 的代码上运行的代码。在plugins.py的最后,可以看到extra_generated_classes被传递给flask方法render_template ,它呈现一个 Jinja2模板。查看模板内部,oneobj.html,extra_generated_classes 是一个包含三个东西的数组:modulename、classname 和 parentname,它们被传递到 bokeh.server.generatejs:
{% block extra_scripts %}
{% for modulename, classname, parentname in extra_generated_classes %}
<script
src="{{ url_for('bokeh.server.generatejs', modulename=modulename, classname=classname, parentname=parentname) }}"
></script>
{% endfor %}
{% endblock %}
bokeh.server.generatejs 是 bokeh/server/views/plugins.py 中的 Python 代码,只为模板 app.js 调用 render_template,您可以在 bokeh/server/templates 中找到该模板。该模板采用模块名、类名和父名,基本上创建将父名(例如 HBox 或 VBox)扩展到类名(您的应用程序)的 js 代码。
关于python - 面向对象 Bokeh 的多个问题 [已过时],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176074/
我的一位教授给了我们一些考试练习题,其中一个问题类似于下面(伪代码): a.setColor(blue); b.setColor(red); a = b; b.setColor(purple); b
我似乎经常使用这个测试 if( object && object !== "null" && object !== "undefined" ){ doSomething(); } 在对象上,我
C# Object/object 是值类型还是引用类型? 我检查过它们可以保留引用,但是这个引用不能用于更改对象。 using System; class MyClass { public s
我在通过 AJAX 发送 json 时遇到问题。 var data = [{"name": "Will", "surname": "Smith", "age": "40"},{"name": "Wil
当我尝试访问我的 View 中的对象 {{result}} 时(我从 Express js 服务器发送该对象),它只显示 [object][object]有谁知道如何获取 JSON 格式的值吗? 这是
我有不同类型的数据(可能是字符串、整数......)。这是一个简单的例子: public static void main(String[] args) { before("one"); }
嗨,我是 json 和 javascript 的新手。 我在这个网站找到了使用json数据作为表格的方法。 我很好奇为什么当我尝试使用 json 数据作为表时,我得到 [Object,Object]
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我听别人说 null == object 比 object == null check 例如: void m1(Object obj ) { if(null == obj) // Is thi
Match 对象 提供了对正则表达式匹配的只读属性的访问。 说明 Match 对象只能通过 RegExp 对象的 Execute 方法来创建,该方法实际上返回了 Match 对象的集合。所有的
Class 对象 使用 Class 语句创建的对象。提供了对类的各种事件的访问。 说明 不允许显式地将一个变量声明为 Class 类型。在 VBScript 的上下文中,“类对象”一词指的是用
Folder 对象 提供对文件夹所有属性的访问。 说明 以下代码举例说明如何获得 Folder 对象并查看它的属性: Function ShowDateCreated(f
File 对象 提供对文件的所有属性的访问。 说明 以下代码举例说明如何获得一个 File 对象并查看它的属性: Function ShowDateCreated(fil
Drive 对象 提供对磁盘驱动器或网络共享的属性的访问。 说明 以下代码举例说明如何使用 Drive 对象访问驱动器的属性: Function ShowFreeSpac
FileSystemObject 对象 提供对计算机文件系统的访问。 说明 以下代码举例说明如何使用 FileSystemObject 对象返回一个 TextStream 对象,此对象可以被读
我是 javascript OOP 的新手,我认为这是一个相对基本的问题,但我无法通过搜索网络找到任何帮助。我是否遗漏了什么,或者我只是以错误的方式解决了这个问题? 这是我的示例代码: functio
我可以很容易地创造出很多不同的对象。例如像这样: var myObject = { myFunction: function () { return ""; } };
function Person(fname, lname) { this.fname = fname, this.lname = lname, this.getName = function()
任何人都可以向我解释为什么下面的代码给出 (object, Object) 吗? (console.log(dope) 给出了它应该的内容,但在 JSON.stringify 和 JSON.parse
我正在尝试完成散点图 exercise来自免费代码营。然而,我现在只自己学习了 d3 几个小时,在遵循 lynda.com 的教程后,我一直在尝试确定如何在工具提示中显示特定数据。 This code
我是一名优秀的程序员,十分优秀!