Search code examples
pythonflaskbokeh

Moving plot bokeh tools


My plot

Hi, I did flask app for my weather station. It generates plot from database. Everything works good on desktop web browser, moving, zooming, hover tool. I have a problem on mobile devices, I can't move my plot, zoom by using zoom box. It's stuck like you can see on the picture. How can I solve my problem?

That's how I generate plot:

def plot(column, color, unit, time, size):
output_file("templates/" + column + "" + time + ".html")
if column == "pressure":
    p = figure(plot_width=800, plot_height=350, toolbar_location="below", x_axis_type="datetime",
               tools='box_zoom,pan,zoom_out,zoom_in,save,reset', sizing_mode="scale_width", x_axis_label="Data",
               y_axis_label=unit, y_range=(980, 1050))
else:
    p = figure(plot_width=800, plot_height=350, toolbar_location="below", x_axis_type="datetime",
               tools='box_zoom,pan,zoom_out,zoom_in,save,reset', sizing_mode="scale_width", x_axis_label="Data",
               y_axis_label=unit)
l1 = []  # TODO wymowne nazwy zmeinnych
l2 = []
d1 = []
d2 = []

conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("SELECT Date FROM measurements ORDER BY ID DESC")
d1 = cursor.fetchmany(size=size)
cursor.execute("SELECT " + column + " FROM measurements ORDER BY ID DESC")
l1 = cursor.fetchmany(size=size)

for i in l1:
    l2.append(i[0])
for i in d1:
    d2.append(i[0])

df = pd.DataFrame()
df['Date'] = d2
df['Date'] = pd.to_datetime(df['Date'], format='%d-%m-%Y %H:%M:%S')
df['DateString'] = df['Date'].dt.strftime("%d-%m-%Y %H:%M:%S")
df["" + column + ""] = l2
cds = ColumnDataSource(df)
p.add_tools(HoverTool(
    tooltips=[("Data", "@DateString"), ('Wartość: ', '@' + column + ' ' + unit + '')],
    formatters={"x": "datetime"}, line_policy="nearest",
    # display a tooltip whenever the cursor is vertically in line with a glyph
    mode='vline'))
p.line("Date", "" + column + "", source=cds, color=color)
save(p)
conn.close()

And then I just include generated html to my page.


Solution

  • This appears to be bug/regression since Bokeh 1.2. The only workaround I can offer at the moment is to use Bokeh 1.1 until it is fixed. I've made a GitHub issue you can follow.