小工具箱中的bokeh小工具不遵守布局

时间:2018-06-22 19:33:29

标签: python bokeh

布置DatePicker小部件时,如果它们位于小部件框中,则布局不遵守row()分组,如示例所示,请参见注释,

from datetime import datetime, timedelta
from bokeh.embed import components
from bokeh.models.widgets.inputs import DatePicker
from bokeh.layouts import column, row, widgetbox, layout

from flask import Flask

app = Flask(__name__)

@app.route("/", methods=['GET'])
def test():
    text = """<!DOCTYPE html>
    <html lang="en">
    <head>
        <link href="https://cdn.pydata.org/bokeh/release/bokeh-0.12.15.min.css" rel="stylesheet" type="text/css">
        <script src="https://cdn.pydata.org/bokeh/release/bokeh-0.12.15.min.js"></script>
        <link href="https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.15.min.css" rel="stylesheet" type="text/css">
        <script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.15.min.js"></script>
        <meta charset="UTF-8">
    </head>
    <body>"""

    d_yesterday = datetime.today() - timedelta(days=1)
    start = DatePicker(title="Start Date", min_date=d_yesterday, max_date=datetime.today(), value=datetime.today())
    end   = DatePicker(title="End Date",   min_date=d_yesterday, max_date=datetime.today(), value=datetime.today())
    left  = DatePicker(title="Left Date",  min_date=d_yesterday, max_date=datetime.today(), value=datetime.today())
    right = DatePicker(title="Right Date", min_date=d_yesterday, max_date=datetime.today(), value=datetime.today())

    doc_layout = layout(sizing_mode='scale_width')
    # This does not work, the row DatePickers appear as a column...
    #doc_layout.children.append(column(widgetbox(start, end)))
    #doc_layout.children.append(row(widgetbox(left, right)))

    # this works, but doesn't use widgetbox...
    doc_layout.children.append(column(start, end))
    doc_layout.children.append(row(left, right))

    _script, _div = components(doc_layout)
    text += "{}{}".format(_script, _div)

    text += """</body></html>"""
    return text

app.run(host="0.0.0.0", port=6800)

python 2.7.11,Windows操作系统,Chrome和Edge中的结果相同。

0 个答案:

没有答案