how to update nicegui table?

278 Views Asked by At

I created a niceGUI table component and wanted to use a button to execute pandas.readexcel to read a specific Excel file and update to this component. However, I am unable to update it at this time, whether using the official update method or executing table. from again_ The Pandas() method is not feasible.

Here is my code:

from nicegui import ui
import pandas as pd

df = pd.DataFrame()
def compare():
    global df
    ui.notify("reading......")
    df = pd.read_excel("1.xlsx")
    mytable.from_pandas(df) # 1#
    ui.update(mytable)
    ui.notify("complete......")
    
with ui.row():
    compare_btn = ui.button(text="test", on_click=compare)

mytable = ui.table.from_pandas(df).style("width:100%;height:100%;") #2

ui.run()

If I directly use from_pandas in the compare event of the button, I will create a new table instead of reloading or updating the content of the original table. Now I hope to update it directly on my mytable table table instead of creating another one

0

There are 0 best solutions below