The “problem” variable don’t take the values of tablaresultado, it is taking the values of data3, but tablaresultado is uptade correctly in the website
----> i do a print for watch values in console
def actualizar_makespan(timestamp, data):
problem = pd.DataFrame(data) #i want "updated table" data, instead of data 3
print(problem)
value = 10 #max values
return value
import dash
from dash import html, dash_table
import pandas as pd
app = dash.Dash(__name__)
#creo el dataframe
data = {'Operario': ['Eficiencia'],
'A': ['65%'],
'B': ['80%'],
'C': ['75%'],
'D': ['100%'],
'E': ['75%'],
'F': ['80%'],
'G': ['60%'],
'H': ['60%'],
'I': ['90%'],
'J': ['95%'],
'K': ['75%'],
'L': ['90%']}
tabla2 = pd.DataFrame(data)
data2= {'Referencia': ['T05', 'T10', 'T50', 'T75', 'T150', 'T200', 'T250', 'T500'],
'Tiempo_estándar': [20, 45, 25, 50, 90, 110, 120, 150],
'Requerimiento': [8, 10, 12, 9, 7, 15, 10, 7],
'A': [1, 1, 2, 1, 1, 2, 1, 1],
'B': [0, 0, 0, 0, 0, 0, 0, 0],
'C': [0, 0, 0, 0, 0, 0, 0, 0],
'D': [0, 0, 0, 0, 0, 0, 0, 0],
'E': [0, 0, 0, 0, 0, 0, 0, 0],
'F': [1, 0, 0, 0, 0, 0, 0, 0],
'G': [0, 0, 0, 0, 0, 0, 0, 0],
'H': [0, 0, 0, 0, 0, 0, 0, 0],
'I': [0, 0, 0, 0, 0, 0, 0, 0],
'J': [0, 0, 0, 0, 0, 0, 0, 0],
'K': [0, 0, 0, 0, 0, 0, 0, 0],
'L': [0, 0, 0, 0, 0, 0, 0, 0],
'Total': [0, 0, 0, 0, 0, 0, 0, 0]}
tabla3 = pd.DataFrame(data2)
data3 = {
'Operario': ['Terminación'],
'A': [0],
'B': [0],
'C': [0],
'D': [0],
'E': [0],
'F': [0],
'G': [0],
'H': [0],
'I': [0],
'J': [0],
'K': [0],
'L': [0]
}
tabla4 = pd.DataFrame(data3)
# Crea la tabla
table = dash_table.DataTable(
data=tabla3.to_dict('records'),
id='tabla-editable',
columns=[
{'name': 'Referencia', 'id': 'Referencia', 'editable': False},
{'name': 'Tiempo_estándar', 'id': 'Tiempo_estándar', 'editable': False},
{'name': 'Requerimiento', 'id': 'Requerimiento', 'editable': False},
{'name': 'A', 'id': 'A', 'editable': True, 'type': 'numeric'},
{'name': 'B', 'id': 'B', 'editable': True, 'type': 'numeric'},
{'name': 'C', 'id': 'C', 'editable': True, 'type': 'numeric'},
{'name': 'D', 'id': 'D', 'editable': True, 'type': 'numeric'},
{'name': 'E', 'id': 'E', 'editable': True, 'type': 'numeric'},
{'name': 'F', 'id': 'F', 'editable': True, 'type': 'numeric'},
{'name': 'G', 'id': 'G', 'editable': True, 'type': 'numeric'},
{'name': 'H', 'id': 'H', 'editable': True, 'type': 'numeric'},
{'name': 'I', 'id': 'I', 'editable': True, 'type': 'numeric'},
{'name': 'J', 'id': 'J', 'editable': True, 'type': 'numeric'},
{'name': 'K', 'id': 'K', 'editable': True, 'type': 'numeric'},
{'name': 'L', 'id': 'L', 'editable': True, 'type': 'numeric'},
{'name': 'Total', 'id': 'Total', 'editable': False}
],
editable=True,
)
table2 = dash_table.DataTable(
id='tablaresultados',
data=tabla4.to_dict('records'),
columns=[{'id': c, 'name': c} for c in tabla4.columns],
style_table={
'maxWidth': '800px',
'margin': '1rem auto',
'overflowX': 'auto'
}
)
# Definir el callback para actualizar la tabla1
@app.callback(
dash.dependencies.Output('tabla-editable', 'data'),
[dash.dependencies.Input('tabla-editable', 'data_timestamp')],
[dash.dependencies.State('tabla-editable', 'data')]
)
def actualizar_tabla1(timestamp, data):
tabla3 = pd.DataFrame(data)
tabla3['Total'] = tabla3[['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']].apply(pd.to_numeric, errors='coerce').sum(axis=1)
return tabla3.to_dict('records')
#Definir el callback para actualizar la tabla2
@app.callback(
dash.dependencies.Output('tablaresultados', 'data'),
[dash.dependencies.Input('tabla-editable', 'data_timestamp')],
[dash.dependencies.State('tabla-editable', 'data')]
)
def actualizar_tabla4(timestamp, data):
tabla3 = pd.DataFrame(data)
columnas = tabla2.columns.tolist()
columnas.pop(0)
listadeTE = tabla3['Tiempo_estándar'].values.tolist()
listasolucion=[x]
for operario in columnas:
listadeA = tabla3[operario].values.tolist()
suma_producto = sum([x * y for x, y in zip(listadeA, listadeTE)])
porcentaje_str = tabla2[operario][0]
porcentaje_num = float(porcentaje_str[:-1])/100.0
listasolucion.append(round(suma_producto/porcentaje_num,2))
index=0
for operario in columnas:
tabla4.loc[0, operario] = listasolucion[index]
index+=1
return tabla4.to_dict('records')
#Definir el callback para actualizar la tabla3
@app.callback(
dash.dependencies.Output('valor-makespan', 'children'),
[dash.dependencies.Input('tablaresultados', 'data_timestamp')],
[dash.dependencies.State('tablaresultados', 'data')]
)
def actualizar_makespan(timestamp, data):
problem = pd.DataFrame(data)
print(problem)
value = 10
return value
# Crea el diseño de la aplicación
app.layout = html.Div(children=[
html.H1(children='Ejemplo de tabla editable en Dash'),
table,
table2,
html.Div([
html.H2('Makespan: ',
style={
'textAlign': 'center',
'color': 'rgb(243, 245, 244)',
'fontSize': '2rem'
}),
html.B(id='valor-makespan',
style={
'textAlign': 'center',
'color': 'rgb(9, 205, 205)',
'fontSize': '3rem',
'display': 'block',
'margin': '1rem'
}),
])
])
# Ejecuta la aplicación
if __name__ == '__main__':
app.run_server(debug=True)