动态更新破折号 table return 空行
Dynamically updating dash table return empty rows
我做了这个小仪表板,我想测试页面末尾动态更新的“结果 table”。
我创建了这些测试线以查看如何更新它,但它似乎无法正确更新。它在输出 table 中显示了另外两行,但未显示任何值。打印 df 时会显示正确的值。
如果你能帮助我就太好了。
干杯,
Mjst
button_berechnen = html.Div([
dbc.Row([
dcc.Input(
id="input_marge",
placeholder= 'marge in 1XX% i.e. 1.4'),
html.Button('Berechnen', id ='submit-marge', n_clicks = 0),
]),
])
#output tabelle
output_table = html.Div([
dash_table.DataTable(
id = 'output_table',
columns = [ {'name' : 'Index', 'id': "index"},
{'name' : 'Produkt', 'id':"produkt"},
{'name' : 'Ebay', 'id':"ebay"},
{'name' : 'Amazon', 'id':"amazon"},
{'name' : 'Real', 'id':"real"},
{'name' : 'Webshop', 'id':"webshop"}],
style_cell = {
'backgroundColor': 'rgb(50,50,50)',
'color': 'white'
},
editable = True
)
])
app.layout = dbc.Container([
button_berechnen,
output_table,
])
@app.callback(Output('output_table', 'data'),
Input('submit-marge', 'n_clicks'),
#Input('produkt_daten', 'data'),
State('input_marge', 'value'))
#berechnen des output tables
def rows_berechnen(n_clicks, marge):
if n_clicks >0 :
df_preise = pd.DataFrame(columns = {'Produkt', 'Ebay', 'Amazon', 'Real', 'Webshop'})
test = {'Produkt' : 'marge', 'Ebay': marge, 'Amazon': marge, 'Real': marge, 'Webshop': marge}
test2 = {'Produkt' : 'marge', 'Ebay': marge, 'Amazon': marge, 'Real': marge, 'Webshop': marge}
df_preise = df_preise.append(test, ignore_index=True)
df_preise = df_preise.append(test2, ignore_index=True)
print(df_preise)
df = df_preise.to_dict(orient ='records')
return df
raise PreventUpdate
if __name__ == '__main__':
app.run_server(debug=True)
定义数据table时,尝试在布局中设置data=[]
。有时 Dash 会出现未明确设置的属性问题。
编辑:
问题出在 columns
的定义方式上。我把它改成了这个,它起作用了:
columns=[{'name': 'Index', 'id': "Index"},
{'name': 'Produkt', 'id': "Produkt"},
{'name': 'Ebay', 'id': "Ebay"},
{'name': 'Amazon', 'id': "Amazon"},
{'name': 'Real', 'id': "Real"},
{'name': 'Webshop', 'id': "Webshop"}],
有没有人尝试过使用用户输入进行简单算术运算的动态 table?
4 = 细胞[1][1] ; 5 = 单元格 [1][2] ;细胞[1][1]+细胞[1][2] = 细胞[1][3]
我做了这个小仪表板,我想测试页面末尾动态更新的“结果 table”。 我创建了这些测试线以查看如何更新它,但它似乎无法正确更新。它在输出 table 中显示了另外两行,但未显示任何值。打印 df 时会显示正确的值。
如果你能帮助我就太好了。
干杯, Mjst
button_berechnen = html.Div([
dbc.Row([
dcc.Input(
id="input_marge",
placeholder= 'marge in 1XX% i.e. 1.4'),
html.Button('Berechnen', id ='submit-marge', n_clicks = 0),
]),
])
#output tabelle
output_table = html.Div([
dash_table.DataTable(
id = 'output_table',
columns = [ {'name' : 'Index', 'id': "index"},
{'name' : 'Produkt', 'id':"produkt"},
{'name' : 'Ebay', 'id':"ebay"},
{'name' : 'Amazon', 'id':"amazon"},
{'name' : 'Real', 'id':"real"},
{'name' : 'Webshop', 'id':"webshop"}],
style_cell = {
'backgroundColor': 'rgb(50,50,50)',
'color': 'white'
},
editable = True
)
])
app.layout = dbc.Container([
button_berechnen,
output_table,
])
@app.callback(Output('output_table', 'data'),
Input('submit-marge', 'n_clicks'),
#Input('produkt_daten', 'data'),
State('input_marge', 'value'))
#berechnen des output tables
def rows_berechnen(n_clicks, marge):
if n_clicks >0 :
df_preise = pd.DataFrame(columns = {'Produkt', 'Ebay', 'Amazon', 'Real', 'Webshop'})
test = {'Produkt' : 'marge', 'Ebay': marge, 'Amazon': marge, 'Real': marge, 'Webshop': marge}
test2 = {'Produkt' : 'marge', 'Ebay': marge, 'Amazon': marge, 'Real': marge, 'Webshop': marge}
df_preise = df_preise.append(test, ignore_index=True)
df_preise = df_preise.append(test2, ignore_index=True)
print(df_preise)
df = df_preise.to_dict(orient ='records')
return df
raise PreventUpdate
if __name__ == '__main__':
app.run_server(debug=True)
定义数据table时,尝试在布局中设置data=[]
。有时 Dash 会出现未明确设置的属性问题。
编辑:
问题出在 columns
的定义方式上。我把它改成了这个,它起作用了:
columns=[{'name': 'Index', 'id': "Index"},
{'name': 'Produkt', 'id': "Produkt"},
{'name': 'Ebay', 'id': "Ebay"},
{'name': 'Amazon', 'id': "Amazon"},
{'name': 'Real', 'id': "Real"},
{'name': 'Webshop', 'id': "Webshop"}],
有没有人尝试过使用用户输入进行简单算术运算的动态 table?
4 = 细胞[1][1] ; 5 = 单元格 [1][2] ;细胞[1][1]+细胞[1][2] = 细胞[1][3]