Plotly Dash - 图像不显示?
我正在学习 Ploty Dash 并尝试了基本的多输出回调。我尝试检索取决于(数字轮和颜色)组合的图像。单选按钮正常并且工作正常,但图像不显示。它只是显示“撕裂图像图标”和方形白色空白。
我的图像以.jpg格式存储在我的C计算机上(路径如下面的代码所示)。我尝试从本课程附加的文件中复制代码,但仍然无法显示该图像。
因为这是我学习Python的第一周,所以我除了四处询问哈哈之外什么也做不了。感谢您的帮助。
app = dash.Dash()
def encode_image(image_file):
encoded = base64.b64encode(open(image_file, 'rb').read())
return 'data:image/png;base64,{}'.format(encoded.decode())
app.layout = html.Div([
dcc.RadioItems(id='wheels',
options=[{'label': i,'value':i} for i in df['wheels'].unique()],
value=1
),
html.Div(id='wheels-output'),
html.Hr(),
dcc.RadioItems(id='colors',
options=[{'label': i,'value':i} for i in df['color'].unique()],
value='blue'),
html.Div(id='colors-output'),
html.Img(id='display-image', src='children', height=300)
], style={'fontFamily':'helvetica','fontsize':18})
@app.callback(Output('wheels-output','children'),
[Input('wheels','value')])
def callback_a(wheels_value):
return "You Chose {}".format(wheels_value)
@app.callback(Output('colors-output','children'),
[Input('colors','value')])
def callback_b(colors_value):
return "You Chose {}".format(colors_value)
@app.callback(Output('display-image','src'),
[Input('wheels','value'),
Input('colors','value')])
def callback_image(wheel, color):
path = '/Python/Udemy-Plotly/Data/Images/'
return encode_image(path+df[(df['wheels']==wheel) &
(df['color']==color)]['image'].value[0])
I'm learning Ploty Dash and tried basic Multiple Output Callback. I tried to retrieve images depended to combination of (Number Wheels and Colors). The radio button is OK and work fine, but image does not show up. It just displayed "ripped image icon" and square white blank.
My images stored in .jpg format at my C computer (path as shown in code below). I tried to copy the code from file attached from this course, but still wont displayed that image.
Since this is my first week learn python, I cannot do anything but asking aroung lol. Thanks for help.
app = dash.Dash()
def encode_image(image_file):
encoded = base64.b64encode(open(image_file, 'rb').read())
return 'data:image/png;base64,{}'.format(encoded.decode())
app.layout = html.Div([
dcc.RadioItems(id='wheels',
options=[{'label': i,'value':i} for i in df['wheels'].unique()],
value=1
),
html.Div(id='wheels-output'),
html.Hr(),
dcc.RadioItems(id='colors',
options=[{'label': i,'value':i} for i in df['color'].unique()],
value='blue'),
html.Div(id='colors-output'),
html.Img(id='display-image', src='children', height=300)
], style={'fontFamily':'helvetica','fontsize':18})
@app.callback(Output('wheels-output','children'),
[Input('wheels','value')])
def callback_a(wheels_value):
return "You Chose {}".format(wheels_value)
@app.callback(Output('colors-output','children'),
[Input('colors','value')])
def callback_b(colors_value):
return "You Chose {}".format(colors_value)
@app.callback(Output('display-image','src'),
[Input('wheels','value'),
Input('colors','value')])
def callback_image(wheel, color):
path = '/Python/Udemy-Plotly/Data/Images/'
return encode_image(path+df[(df['wheels']==wheel) &
(df['color']==color)]['image'].value[0])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将下面的行修改
为
Try modify bellow line
to
我提供了完整的路径名。
也
改为
I provided the full path name.
Also Changed
to