python - 如何使用python dash循环显示多个图像

标签 python html plotly-dash

我这样做是为了用破折号显示多个图像,但它显然不起作用,因为它只显示一张图像。

for i in images:
    app.layout = html.Div([
        html.Div([
            html.A([
                html.Img(
                    src=app.get_asset_url(i),
                    style={
                        'height' : '40%',
                        'width' : '40%',
                        'float' : 'left',
                        'position' : 'relative',
                        'padding-top' : 0,
                        'padding-right' : 0
                    }
                )
            ], href='https://www.google.com'),
        ])
    ]) 

最简单的方法是什么?考虑到这些是图像而不是绘图。

最佳答案

我设法让它像这样工作

def generate_thumbnail(image):
    return html.Div([
        html.A([
            html.Img(
                src = app.get_asset_url(i),
                style = {
                    'height': '40%',
                    'width': '40%',
                    'float': 'left',
                    'position': 'relative',
                    'padding-top': 0,
                    'padding-right': 0
                }
            )
        ], href = 'https://www.google.com'),
    ])

images_div = []
for i in images:
    images_div.append(generate_thumbnail(i))
app.layout = html.Div(images_div)

关于python - 如何使用python dash循环显示多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54550795/

相关文章:

java - 如何为 ImageSpan 设置背景颜色和下划线

python - Plotly Dash 中心 dcc.输入文本字段

python - 如何启用对 Dash DataTable 上特定行的编辑

javascript - Jinja2 和 HTML Div 标签

python - 更改/调整管理界面上的日期小部件

html - Bootstrap 轮播动画

javascript - jSignature 未从显示 :none to display:block correctly in multi-page form 移动

python-3.x - 创建一个绘制线图,其中线按类别着色?

python - 在 matplotlib 中更改字体

python - 将 args 传递给 DLL 函数调用时没有足够的参数(缺少 20 个字节)