admin管理员组

文章数量:1131210

In my case, I have been trying to create a tools for finding data in db. However, when I'm trying to find new data, the old result is not replace by the new one, it likely add new result under the latest output.

The second problem is, when the data table found, it automatically open download box. But I just want it to show the "download" button, it just download if only I click the the "Download" button

Here is my code, pls help!

def testSubmit(userInput, dateInput):
    print(f"UserInput: {userInput} --- dataType: {type(userInput)}")
    print(f"dateStart: {dateInput} --- dataType: {type(dateInput)}")
    dataTableTest = pd.read_csv('./assetsTest/dataTest.csv').drop("id_date", axis=1)
    dataTableTest['date'] = dataTableTest['date'].apply(lambda x: pd.to_datetime(x).strftime("%d-%m-%Y"))
    dataRecord = dataTableTest.copy() # .to_dict(orient='records')
    dataBasicStat = dataTableTest.describe().reset_index()

    def download_button(data):
        data.to_excel(f'./tmp/{userInput}.xlsx')
        ui.download(f'./tmp/{userInput}.xlsx')
        ui.navigate.reload()

    with table_rows_container:
        ui.table.from_pandas(dataRecord, pagination=10)

        ui.table.from_pandas(dataBasicStat, pagination=10)

    with buttonContainer:
        ui.button('Download', on_click = download_button(dataTableTest), color='secondary').classes('mt-4')

    with figure_rows_container:
        figureTest = go.Figure()
        figureTest.add_trace(
            go.Scatter(
                x = dataTableTest['date'],
                y = dataTableTest['VND=D1'],
                mode = 'lines',
                name  = 'VND=D1'
            )
        )
        ui.plotly(figureTest)

# Element UI

        with ui.element('div') as buttonContainer:
            ui.button('Find Data', on_click=lambda: testSubmit(userInput.value, expectDateRange.value), color='secondary').classes('mt-4')

        with ui.element('div'):
            ui.label('Data Table').classes('text-lg font-bold p-2')
        table_rows_container = ui.grid(columns=2).classes("w-full")

        ui.separator()
        with ui.element('div'):
            ui.label('Figure').classes('text-lg font-bold p-2')

        figure_rows_container = ui.row().style("justify-content: center")

        chart_ui = ui.html('')  # Placeholder for the Plotly char

本文标签: pythonHow to clear the old result using niceGUIStack Overflow