Hi,
I am new to dash, and I am trying to build a web application where one of the figures has subplots, and each of these subplots is actually an image.
Here is the code snippet that I am using for my purpose:
@app.callback(Output('galaxy_images', 'figure'),
[Input('gal_name', 'value'),
Input('r_mag_range', 'value')])
def display_galaxy_images(gal_name, r_mag_range):
fld, gal_id = re.findall(r'\d+', gal_name)
obj = "FDS{}DWARF{}".format(fld, gal_id).ljust(12)
obj_direc = "/home/data/{}/{}/".format(r_mag_range, obj)
bands = get_all_bands(obj_direc)
n = len(bands)
# b='r'
# img, hdr = fits.getdata(obj_direc+"{}F{}D{}_final.fits".format(b, fld, gal_id),\
# header=True)
# fig = px.imshow(img, origin='lower', zmin=-0.5e-11, zmax=1e-11)
fig = make_subplots(rows=1, cols=n, shared_yaxes=True)
for i in range(n):
b = bands[i]
img = fits.getdata(obj_direc+"{}F{}D{}_final.fits".format(b, fld, gal_id))
fig.add_trace(
go.Image(z=img),\
# px.imshow(img, origin='lower', zmin=-0.5e-11, zmax=1e-11),\
row=1, col=i+1
)
fig.update_layout(height=400, width=n*400,
title_text="Multi-band images of the {}".format(gal_name))
return fig
The commented lines in the code above are able to produce the desired result i.e. displaying one image. But when I try to put all the images in the subplots using plotly_express
, I get an error: Callback error updating galaxy_images.figure
I also tried using plotly’s graphing_objects
, and it did not give me any error but the images are still not displayed although the figure layout is (see image below).
To test if using subplots in dash is an issue, I tried this code:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2)
for i in range(2):
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=i+1
)
fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
fig.show()
And this works perfectly fine.
Does anyone know how to make this work?