question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bokeh Spacer sets height to one pixel with scale_width set

See original GitHub issue

ALL software version info (bokeh, python, OS, browser, any other relevant packages)

bokeh: 0.12.15 python: 3.6.4 OS: Mac OS 10.12.6 browser: Google Chrome 65.0.3325.181 (Official Build) (64-bit)

Description of expected behavior and the observed behavior

I would expect to see a moderate amount of vertical separation between widgets, keeping the width/height ratio constant. However when I inspect the location the element should be, I see that it has a height of 1 pixel, regardless of the aspect ratio. I did not have this issue when putting a Spacer in a row. Putting the plot in the column too and skipping the row does not fix the problem.

Complete, minimal, self-contained example code that reproduces the issue

I modified the sliders.py example code to put the widgets in two separate boxes, then grouped them and a spacer in a column.

import numpy as np

from bokeh.io import curdoc
from bokeh.layouts import row, column, widgetbox, Spacer
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Slider, TextInput
from bokeh.plotting import figure

# Set up data
N = 200
x = np.linspace(0, 4*np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))


# Set up plot
plot = figure(plot_height=400, plot_width=400, title="my sine wave",
              tools="crosshair,pan,reset,save,wheel_zoom",
              x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)


# Set up widgets
text = TextInput(title="title", value='my sine wave')
offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1)
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1)
phase = Slider(title="phase", value=0.0, start=0.0, end=2*np.pi)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1)


# Set up callbacks
def update_title(attrname, old, new):
    plot.title.text = text.value

text.on_change('value', update_title)

def update_data(attrname, old, new):

    # Get the current slider values
    a = amplitude.value
    b = offset.value
    w = phase.value
    k = freq.value

    # Generate the new curve
    x = np.linspace(0, 4*np.pi, N)
    y = a*np.sin(k*x + w) + b

    source.data = dict(x=x, y=y)

for w in [offset, amplitude, phase, freq]:
    w.on_change('value', update_data)


# Set up layouts and add to document
##### BEGIN RELEVANT SECTION #####
input1 = widgetbox(text, offset)
input2 = widgetbox(amplitude, phase, freq)
inputs = column(input1, 
              Spacer(width=400, height=400, sizing_mode='scale_width'),
              input2, sizing_mode='scale_width')
##### END RELEVANT SECTION #####

curdoc().add_root(row(inputs, plot, sizing_mode='scale_width'))
curdoc().title = "Sliders"

Screenshots or screencasts of the bug in action

screen shot 2018-04-17 at 4 29 32 pm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Jan 31, 2019

This appears to be fixed by #8085:

screen shot 2019-01-30 at 21 04 55

however @mattpap it appears Spacer was removed from bokeh.layouts, we should restore this transitive import from bokeh.models.layouts

0reactions
mattpapcommented, Apr 18, 2018

Using Div may serve as a temporary workaround, however, this solution may not work as expected in newer versions of bokeh. Currently this works, because empty Div has intrinsic padding, which seems to be a bug on its own.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bokeh.layouts — Bokeh 3.0.3 Documentation
Functions for arranging bokeh layout objects. column: grid: gridplot: layout: row: Spacer:
Read more >
How to use the bokeh.layouts.row function in bokeh - Snyk
To help you get started, we've selected a few bokeh.layouts.row examples, based on popular ... Spacer(width=20, height=60), self.data_time_dd, bokeh.models.
Read more >
Tensorplot: Interactive Visualization of High-Dimensional Data
We propose a web-based GUI to interactively explore multi-dimensional data using an efficient com- pressed format called tensor ...
Read more >
bokeh layout for plot and widget arrangement - Stack Overflow
You can change the last line in your callback to: doc_layout.children[0].children[-1].children.append(p). And change your layout to:
Read more >
Lesson 30: JavaScript for stand-alone Bokeh apps
Panel, with Bokeh output, allow us to write Python code that can ... I hope you recognize how powerful this is for exploring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found