✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🏦 Standard & Poor's chooses Dash Enterprise for ESG analysis. Learn why, sign up for the June 23 Webinar here!

Dash how to use imshow or Image?

Hi,

I’d like to use the newly introduced imshow/Image in a dash application.

In jupyter lab this renders nicely

import plotly.graph_objects as go
img_rgb = [[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
           [[0, 255, 0], [0, 0, 255], [255, 0, 0]]]
fig = go.Figure(go.Image(z=img_rgb))
fig.show()

grafik

whereas in dash I only see the empty graph component.

%%writefile app.py

import plotly
import plotly.graph_objects as go
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output

print('plotly=', plotly.__version__)
print('dash=', dash.__version__)
print('dash_html_components=', html.__version__)
print('dash_core_components=', dcc.__version__)

app = dash.Dash(
    __name__, external_stylesheets=["https://codepen.io/chriddyp/pen/bWLwgP.css"]
)

img_rgb = [[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
           [[0, 255, 0], [0, 0, 255], [255, 0, 0]]]

app.layout = html.Div(
    [
        html.H1("go.Image"),
        dcc.Graph(id="graph", figure = go.Figure(go.Image(z=img_rgb)), style={"width": "75%", "display": "inline-block"}),
    ]
)

app.run_server(debug=True)

Versions:
plotly= 4.3.0
dash= 1.4.1
dash_html_components= 1.0.1
dash_core_components= 1.3.1

.

I get the same behaviour when I’m trying to pass the plotly.express imshow to dcc.Graph figure. What am I missing?

1 Like

WOW this is weird. I could actually reproduce the issue as well, but on a fresh environment the problem disappeared. Maybe a problem with conflicting versions of dash and dcc? Could you please try to uninstall dash, dash_html_components and dash_core_components, and then install only dash (which installs automatically compatible versions of html and dcc)? Or of course do this first in a fresh environment to debug.

1 Like

In a fresh env it worked using the newer dash version. Thanks for looking into it

plotly= 4.3.0
dash= 1.7.0
dash_html_components= 1.0.2
dash_core_components= 1.6.0

2 Likes

Cool, glad it worked out!

I had the identical problem still 6 months later… my conda environment had very stale packages. For some reason the “plotly” source on anaconda has VERY stale versions of dash and dash_*_components. I wound up having to burn down anaconda (complete removal), then I installed miniconda and picked up to date versions of the packages from alternative sources.

1 Like

Same issue persists. I originally installed dash via conda. Now I ran pip install dash, which updated dash-html-components, dash-core-components, and so on. It’s now working.