【发布时间】:2019-03-05 22:47:03
【问题描述】:
我有一个 Bokeh 应用程序 (bokeh==1.0.1),我在其中使用 gridplot 来呈现滑块小部件框和几个图形。我正在使用sizing_mode='stretch_both'。如何消除小部件行和其他图形面板之间的空白?这是截图:
我为小部件创建了一个布局:
blank_button = bkm.widgets.RadioButtonGroup()
blank_wb = widgetbox(blank_button, width=50, height=100, sizing_mode='fixed') # placeholder for space
date_slider_wb = widgetbox(date_slider, width=400, height=100, sizing_mode='fixed')
apply_button = bkm.widgets.Button(label="APPLY")
apply_wb = widgetbox(apply_button, width=100, height=100, sizing_mode='fixed')
hor_layout_date_slider = (
row(
column(blank_wb),
column(date_slider_wb),
column(apply_wb),
)
)
然后我将hor_layout_date_slider 包含在gridplot 中:
grid = gridplot(
children = [
hor_layout_date_slider,
airtemp_fig,
windspeed_fig,
winddir_fig,
interval_fig,
precip_fig,
pressure_fig
],
ncols=1,
sizing_mode='stretch_both',
merge_tools=False,
)
curdoc().add_root(grid)
我正在使用散景服务器并将散景文档呈现在我的 html 模板中的单个 div 中:
<div class="placeholderbokehapp rounded" id="tbc-id">
<script src="http://localhost:5858/stormtracker_bokehapp/autoload.js?bokeh-autoload-element=1000&bokeh-app-path=/stormtracker_bokehapp&bokeh-absolute-url=http://localhost:5858/stormtracker_bokehapp&resources=none" id="1000"></script>
</div>
作为一种尝试性的破解解决方案,我已经能够通过自定义 css 规则来定义包含 hor_layout_date_slider 的 div 的高度,但是仍然有一个持续存在的元素的“占位符”(我无法访问检查元素)。
我还尝试使用仅包含滑块的简单小部件框(未定义高度和宽度并使用sizing_mode='stretch_both'),而不是上面定义的完整hor_layout_date_slider。但是,这会导致滑块元素后面出现相同的空白。
奇怪的是,sizing_mode='scale_width' 不会出现这个问题(滑块在布局中很紧)。
在使用sizing_mode='stretch_both' 时,是否有我不知道的散景设置来控制此布局中的间距?
更新:
如果我将小部件和网格分别添加为:
curdoc().add_root(hor_layout_date_slider)
curdoc().add_root(grid)
然后小部件在第一个图形面板下方呈现(您可以在下面的屏幕截图中看到部分滑块小部件)。
【问题讨论】:
-
widgetbox 周围的空白是
gridplot()中的所有元素在使用sizing_mode='stretch_both'时被强制为相同高度的结果。我已经通过单独的 SO 帖子解决了这个问题:stackoverflow.com/questions/55079873/… -
更新:使用
sizing_mode='stretch_width',一切正常。可以将所有元素(包括DateRangeSlider)放在一个gridplot中,然后将单个对象添加到curdoc()中。