Hey there,
I have an app where I want to show three to four gray-scale images with px.imshow(binary_string=True)
. I have to update the images via a callback and I’m running into performance issues if the resolution gets higher.
Up to a size of approximately 1100 x 3500
pixels, the loading time is OK. If I try do show higher resolution images, the loading time explodes. I know that’s normal but I would really like to reduce loading times / increase resolution.
Maybe someone has an idea.
Here an example:
import dash
from dash import Input, Output, dcc, ALL
import dash_bootstrap_components as dbc
import plotly.express as px
import numpy as np
WIDTH = 1100
HEIGHT = 3500
def create_graph():
return dcc.Graph(
figure=px.imshow(
img=np.random.randint(0, 255, size=(WIDTH, HEIGHT)).astype(np.uint8),
binary_string=True,
binary_compression_level=4
)
)
app = dash.Dash(
__name__,
external_stylesheets=[dbc.themes.BOOTSTRAP]
)
app.layout = dbc.Container(
[
dbc.Row(
[
dbc.Col(
id={'type': 'graph_container', 'index': 0},
width=6
),
dbc.Col(
id={'type': 'graph_container', 'index': 1},
width=6
),
],
),
dbc.Row(
[
dbc.Col(
id={'type': 'graph_container', 'index': 2},
width=6
),
dbc.Col(
id={'type': 'graph_container', 'index': 3},
width=6
),
],
),
dbc.Row(
dbc.Button(
id={'type': 'btn', 'index': 0},
children='click'
)
),
],
fluid=True
)
@app.callback(
Output({'type': 'graph_container', 'index': ALL}, 'children'),
Input({'type': 'btn', 'index': ALL}, 'n_clicks'),
prevent_initial_call=True
)
def update_figures(_):
return create_graph(), create_graph(), create_graph(), create_graph()
if __name__ == "__main__":
app.run(debug=False)