What are you trying to do?
I have a static html bokeh page generated by a python script that embeds some javascript. In it there are two plots in a column layout. Clicking on a point on the bottom plot causes the top plot to be populated with some information associated with that point.
What have you tried that did NOT work as expected?
In both pics the text on the bottom is cut off at the left. After the plot resizes, the new title is cut off on the right (there should be a colon and some numbers after the “p-val)” ) and the y-axis label is cut-off on the left. It seems that the column layout is not resizing to take into account the fact that the title is now longer and that the y-axis units are now more characters also (a change from ‘1.2’ to ‘169.2’)
How do I have the layout resize appropriately so that none of the text is cut off?
Thanks for the help!!
Minimal, Reproducible Example
import bokeh.embed as embed
import bokeh.events as events
import bokeh.io as bio
import bokeh.layouts as layouts
import bokeh.models as models
import bokeh.models.callbacks as callbacks
import bokeh.models.tools as tools
import bokeh.plotting as plotting
import bokeh.resources
top_plot = bokeh.plotting.figure(
width = 400,
height = 400,
title = "something or other",
x_axis_label = "some label",
y_axis_label = "some other label"
)
top_plot.add_layout(bokeh.models.Title(
text="some very long text at the bottom of the plot that will get cutoff",
align="right"
), 'below')
top_source = bokeh.models.ColumnDataSource({
'x': [1,2],
'y': [1,2]
})
top_circles = top_plot.circle('x', 'y', source=top_source)
bottom_plot = bokeh.plotting.figure(
width = 400,
height = 400,
)
bottom_source = bokeh.models.ColumnDataSource({
'x': [1,2], 'y': [1,2]
})
bottom_circles = bottom_plot.circle('x', 'y', source=bottom_source)
tap_tool = bokeh.models.tools.TapTool()
bottom_plot.add_tools(tap_tool)
bottom_plot.toolbar.active_tap = tap_tool
tap_callback = bokeh.models.CustomJS(
args=dict(top_plot=top_plot, top_source=top_source),
code="""
console.log('foo');
var new_dict = { 'x': [1,2,3,4], 'y':[1000.001, 1000.002, 1000.003, 1000.004] } ;
top_source.data = new_dict;
top_source.change.emit();
top_plot.title.text = "some very long title that won't all be fully displayed";
"""
)
bottom_source.selected.js_on_change('indices', tap_callback)
layout = bokeh.layouts.column(
top_plot,
bottom_plot
)
html = embed.file_html(layout, bokeh.resources.CDN, 'bokeh test 2')
with open("...", 'w') as out_file:
out_file.write(html)