【问题标题】:How to display multiple images with a loop with python dash如何使用 python dash 循环显示多个图像
【发布时间】:2019-02-06 09:58:15
【问题描述】:

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

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'),
        ])
    ]) 

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

【问题讨论】:

    标签: python html plotly-dash


    【解决方案1】:

    我设法让它像这样工作

    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)
    

    【讨论】:

      猜你喜欢
      • 2021-10-12
      • 2012-05-25
      • 2019-10-08
      • 2023-01-19
      • 2011-06-08
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多