'Dash doesn't show figure created with px.imshow
As in the title, Dash doesn't display a figure (picture) created with px.imshow. Below is my code.
import plotly.graph_objects as go # or plotly.express as px
import plotly.express as px
import numpy as np
import dash
import dash_core_components as dcc
import dash_html_components as html
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]]
], dtype=np.uint8)
fig = px.imshow(img_rgb)
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True)
I used this documentation page. At the very bottom, it says:
Everywhere in this page that you see fig.show(), you can display the same figure in a Dash application by passing it to the figure argument of the Graph component from the built-in dash_core_components package like this:
import plotly.graph_objects as go # or plotly.express as px
fig = go.Figure() # or any Plotly Express function e.g. px.bar(...)
# fig.add_trace( ... )
# fig.update_layout( ... )
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True, use_reloader=False) # Turn off reloader if inside Jupyter
So what am I doing wrong?
Solution 1:[1]
The only thing that I changed to make it run is:
from dash import dcc
from dash import html
instead of
import dash_core_components as dcc
import dash_html_components as html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | atrossi |
