python - Bokeh : sizing_mode ="stretch_both" is not working in tabs

标签 python tabs bokeh

我想要一个“全屏” Bokeh 应用程序,其中包含一个绘图区域和一个使用选项卡的控制区域。

from bokeh.plotting import figure
from bokeh.io import show
from bokeh.layouts import row, widgetbox
from bokeh.models.widgets import Button, Panel, Tabs

tools_to_show = 'hover, box_zoom, save, reset, pan'
p = figure(tools=tools_to_show, output_backend = "webgl")
p.line([1, 2, 3, 4], [9, 5, 7, 6])

b_valid = Button(label="valid")
b_select = Button(label="select")
wbox1 = widgetbox(b_valid)
wbox2 = widgetbox(b_select)
tab1 = Panel(title="tab valid", child=wbox1)
tab2 = Panel(title="tab select", child=wbox2)
tabs = Tabs(tabs=[tab1, tab2])

my_plot = row(p, tabs, sizing_mode="stretch_both")

show(my_plot)

尽管使用了 sizing_mode="stretch_both",选项卡中的小部件并未使用所有可用空间。

我尝试将 sizing_mode="stretch_both"放置在面板中的小部件框中,但没有成功。 我也尝试使用 sizing_mode="scale_width",但没有用。

有什么想法吗?

最佳答案

我找到了一个基于 embedded system of bokeh >0.13 的解决方法您可以在其中将 Bokeh 应用程序的各个组件嵌入到多个 html 元素中,并在 bootstrap grid system 上.

Tab 系统是使用 bootstrap collapse 模拟的功能和按钮。

用于说明的一些代码,用作 Bokeh 服务器应用程序( Bokeh 服务 --show my_folder):

index.html

{% extends base %}

<!-- goes in head -->
{% block preamble %}

<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="example_code/static/css/bootstrap.min.css">
{% endblock %}

<!-- goes in body -->
{% block contents %}
<div class="container-fluid">
    <div class="row">

        <div class="col-1">
            <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapse1"
                    aria-expanded="false" aria-controls="collapse1">
                collapseBtn
            </button>
            <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapse2"
                    aria-expanded="false" aria-controls="collapse2">
                collapsegraph
            </button>
        </div>

        <div class="col" id="main_topic">
      
            <div class="container-fluid collapse" id="collapse1" data-parent="#main_topic">
                <div class="row">
                    <div class="col">
                        {{ embed(roots.bidule) }}
                    </div>
                    <div class="col-2">
                        <p>un peu de texte html</p>
                    </div>
                </div>
            </div>
            
            <div class="container-fluid contenu collapse" id="collapse2" data-parent="#main_topic">
                <div class="row">
                    <div class="col">
                        {{ embed(roots.bloc1) }}
                    </div>

                    <div class="droite col-2">
                        {{ embed(roots.bloc2) }}
                    </div>
                </div>
            </div>
            
        </div>
    </div>
</div>

<script src="example_code/static/js/jquery-3.3.1.slim.min.js"></script>
<script src="example_code/static/js/popper.min.js"></script>
<script src="example_code/static/js/bootstrap.min.js"></script>
{% endblock %}

主要.py

import pandas as pd

from bokeh.plotting import curdoc, figure
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Button
from bokeh.layouts import row, column, widgetbox, layout

# importer un fichier csv et les préparer pour bokeh
file = "data/data.txt"
df = pd.read_csv(file, sep='\t', header=2, index_col =0, decimal=",")
source2 = ColumnDataSource(df)

# BLOC 1
p = figure(output_backend = "webgl",  sizing_mode="stretch_both", name="bloc1")
p.line(x='Datation', y='Temp_enceinte', source = source2, color="blue")

# BLOC 2
bouton1 = Button(label="Mon beau bouton")
bouton2 = Button(label="Roi")
bouton3 = Button(label="des forêts")
o = widgetbox(bouton1, bouton2, bouton3, sizing_mode = "stretch_both", name="bloc2")

# BIDULE
q = figure(output_backend = "webgl",  sizing_mode="stretch_both")
q.line(x='Datation', y='Temp_enceinte', source = source2, color="blue")
r = figure(output_backend = "webgl",  sizing_mode="stretch_both")
r.line(x='Datation', y='Temp_enceinte', source = source2, color="blue")
c = row(q, r, sizing_mode="stretch_both", name="bidule")

###########
# export
###########

curdoc().add_root(p)
curdoc().add_root(o)
curdoc().add_root(c)

关于python - Bokeh : sizing_mode ="stretch_both" is not working in tabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47732408/

相关文章:

python - 如何使用 numpy 分别计算每年的平均月温度?

jquery - 单击选项卡和背景更改(不是选项卡的背景)

python - Bokeh:在单个 Python 回调中多次更新图形

python从子部件调用父方法

python - 是有多个脚本文件还是每个函数只有一个大脚本文件更好?

python - 尝试授权自己进入共享点站点时收到 key 错误

Selenium 网络驱动程序 : Open new tab instead of a new window

jquery - 怎么了? "add class when empty"脚本

javascript - Python Bokeh CustomJS : Debugging a JavaScript callback for the Taping-Tool