Toggle dark mode

Hi,

📢 Taipy v2.1 is about to be launched! 🚀 ETA:

Day(s)

:

Hour(s)

:

Minute(s)

:

Second(s)

M
August 19, 2022

Editing tables

Welcome to Taipy Forums Taipy GUI Editing tables

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #235645
    Dr-IrvDr-Irv
    Participant

    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?

    #235646
    martinshellmartinshell
    Participant

    Thanks for raising this issue. As you note, the unederlying data is updated but the table control does not automatically refresh. Taipy GUI is not “aware” of your edit as while the content of the DataFrame has changed, Taipy is still seeing the same DataFrame. Refreshing the browser causes Taipy to repopulate the table.
    You are not doing anything wrong. If you would like to force Taipy GUI to refresh the table on edit, the simplest way is to make a copy of the DataFrame, edit that copy and replace the original with this “new” DataFrame In your example:

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.