Search code examples
pandasdataframetaipy

Editing tables in Taipy


I am displaying a Pandas DataFrame called Amdres. I have in my Markdown.

<|{amdres}|table|height=400px|width=500px|on_edit=myedit|>

I have a python function myedit that updates the table when someone edits a cell:

def myedit(state: State, varname: str, action: str, payload: dict) -> bool:
state.amdres.loc[payload[“index”], payload[“col”]] = payload[“value”]
return True

I have a global on_change function:

def on_change(state: State, var_name: str, var_value: Any):
print(“changed”)

When I edit the cell and change the value, myedit() is called and the data contents of amdres are updated. But the UI does NOT update.

If I refresh the page in the browser, the new value is shown in the table.

Am I doing something wrong?


Solution

  • You should use a = assignment to propagate the changes to the GUI automatically.

    def myedit(state: State, varname: str, action: str, payload: dict):
        temp = state.amdres.copy()
        temp.loc[payload[“index”], payload[“col”]] = payload[“value”]
        state.amdres = temp