python dash输入带有for循环,并通过将行,列和矩阵的数量作为参数发送

发布于 2025-01-22 14:11:41 字数 1915 浏览 2 评论 0原文

我想通过将行,列和矩阵作为参数发送的数量来创建一个带有for循环的输入。我写的是下面的代码。我在哪里做错了(我想创建图片中的输入框)

matris_toplam = html.Div([
    html.Div(
        [html.Hr(), 
            html.Label('Matrix Row Number'),
            html.Br(),
            dcc.Input(id='msatir', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Satır Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Column Sayısı'),
            html.Br(),
            dcc.Input(id='msutun', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sütun Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Number'),
            html.Br(),
            dcc.Input(id='msayi', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sayısı', href=''),
            html.Br(),


        ],
        className='mt-2 ml-2',
    ),

])

def matrixbox(row,col,sayi):
    b=row*col*sayi
    return [dcc.Input(type='text', id='input%i' % i)for i in range(b)]

@app.callback(
    [dash.dependencies.Output('input%i' %i, 'children')for i in range(row*col*sayi)],
    [Input("msatir", "value"),Input("msutun", "value"),Input("msayi", "value")],
    
)

def update_output(row,col,sayi):
    if row != None and col != None and sayi != None:
        a=matrixbox(row,col,sayi)
        return '{}'.format(a)

“在此处输入图像描述”

I want to create an input with a for loop by sending the number of rows, columns and matrices as parameters.I write is the code below.Where am i doing wrong (I want to create input boxes like in the picture)

matris_toplam = html.Div([
    html.Div(
        [html.Hr(), 
            html.Label('Matrix Row Number'),
            html.Br(),
            dcc.Input(id='msatir', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Satır Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Column Sayısı'),
            html.Br(),
            dcc.Input(id='msutun', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sütun Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Number'),
            html.Br(),
            dcc.Input(id='msayi', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sayısı', href=''),
            html.Br(),


        ],
        className='mt-2 ml-2',
    ),

])

def matrixbox(row,col,sayi):
    b=row*col*sayi
    return [dcc.Input(type='text', id='input%i' % i)for i in range(b)]

@app.callback(
    [dash.dependencies.Output('input%i' %i, 'children')for i in range(row*col*sayi)],
    [Input("msatir", "value"),Input("msutun", "value"),Input("msayi", "value")],
    
)

def update_output(row,col,sayi):
    if row != None and col != None and sayi != None:
        a=matrixbox(row,col,sayi)
        return '{}'.format(a)

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风不识月 2025-01-29 14:11:41

我会让您的样式:)。这应该起作用。

from dash import Dash, html, dcc
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc


app = Dash(__name__)

app.layout =  html.Div([
    html.Div(
        [html.Hr(), 
            html.Label('Matrix Row Number'),
            html.Br(),
            dcc.Input(id='msatir', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Satır Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Column Sayısı'),
            html.Br(),
            dcc.Input(id='msutun', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sütun Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Number'),
            html.Br(),
            dcc.Input(id='msayi', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sayısı', href=''),
            html.Br(),
            

        ],
        className='mt-2 ml-2',
    ),
    html.Div(id='container', style={'display':'flex'})

])

@app.callback(
    Output('container', 'children'),
    [Input("msatir", "value"),Input("msutun", "value"),Input("msayi", "value")],
    
)


def update_output(row,col,sayi):
    final = []
    lst = list()
    if row != None and col != None and sayi != None:
        for k in range(sayi+1):
            
            if k != sayi:
                for i in range(col):
                    lst.append(dbc.Row([dbc.Col(dbc.Input(type='number', id=f'input{k}{j}{i}',
                                        style={'textAlign': 'center','placeholder':'input'})) for j in range(row)]))
            else:
                for i in range(col):
                    lst.append(dbc.Row([dbc.Col(dbc.Input(type='text', id=f'input{k}{j}{i}',placeholder='output',
                                        style={'textAlign': 'center', 'border': '1px solid #588BAE'})) for j in range(row)]))

            final.append(html.Div(lst,style={'display': 'flex','margin-right': '40px'}))
            
            lst = []
        
        return final

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)

I will let the styling for you :). This should work.

from dash import Dash, html, dcc
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc


app = Dash(__name__)

app.layout =  html.Div([
    html.Div(
        [html.Hr(), 
            html.Label('Matrix Row Number'),
            html.Br(),
            dcc.Input(id='msatir', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Satır Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Column Sayısı'),
            html.Br(),
            dcc.Input(id='msutun', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sütun Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Number'),
            html.Br(),
            dcc.Input(id='msayi', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sayısı', href=''),
            html.Br(),
            

        ],
        className='mt-2 ml-2',
    ),
    html.Div(id='container', style={'display':'flex'})

])

@app.callback(
    Output('container', 'children'),
    [Input("msatir", "value"),Input("msutun", "value"),Input("msayi", "value")],
    
)


def update_output(row,col,sayi):
    final = []
    lst = list()
    if row != None and col != None and sayi != None:
        for k in range(sayi+1):
            
            if k != sayi:
                for i in range(col):
                    lst.append(dbc.Row([dbc.Col(dbc.Input(type='number', id=f'input{k}{j}{i}',
                                        style={'textAlign': 'center','placeholder':'input'})) for j in range(row)]))
            else:
                for i in range(col):
                    lst.append(dbc.Row([dbc.Col(dbc.Input(type='text', id=f'input{k}{j}{i}',placeholder='output',
                                        style={'textAlign': 'center', 'border': '1px solid #588BAE'})) for j in range(row)]))

            final.append(html.Div(lst,style={'display': 'flex','margin-right': '40px'}))
            
            lst = []
        
        return final

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文