I am trying to display images by URL reference using the div widget and have them dynamically sized. The issue I am having is that whatever size you have your window at when you load the page, the div element with the img is 0 x 0 at that size. Changing the window to any other size adjusts it as expected, but if you go back to the initial dimensions it disappears. Is there something wrong with how I am setting up the resize properties (max-width
in css and stretch_both
in the Bokeh column instance) ?
Here is a screen-grab I took illustrating the issue: link
Here is a minimal example using bokeh serve in directory format (bokeh version 2.3.2):
resize_test
templates
index.html
main.py
main.py:
from bokeh.plotting import curdoc
from bokeh.models.widgets import Div, Select
from bokeh.layouts import row, column
options = [
('<img src="https://eoimages.gsfc.nasa.gov/images/imagerecords/148000/148336/menindeelakes_oli_201933_lrg.jpg">', "Menidee Lakes"),
('<img src="https://eoimages.gsfc.nasa.gov/images/imagerecords/148000/148350/erie_tmo_2021132_lrg.jpg">', "Lake Erie"),
]
select = Select(title="NASA Image", options=options, value=options[0][0])
image = Div(text=select.value, width=1000, height=1000)
def update_image(url):
image.text = url
select.on_change('value', lambda attr, old, new: update_image(select.value))
box = column([select], width=300)
img = column(image, sizing_mode="stretch_both")
curdoc().add_root(row(box, img, name="resize_test"))
index.html:
{% extends base %}
{% block postamble %}
<style>
img {
max-width: 100%;
}
</style>
{% endblock %}
{% block contents %}
<div id="bokeh-app">
{{ embed(roots.resize_test) }}
</div>
{% endblock %}