reflex icon indicating copy to clipboard operation
reflex copied to clipboard

How to refresh rx.data_editor

Open tien-tran0906 opened this issue 2 years ago β€’ 2 comments

Repo link: https://github.com/tien-tran0906/reflex_test (especially files_tab.py)

Problem: I have a data_editor component that has a check box column at the beginning. I want to have the data_editor render the changes, when the user check/uncheck the checkbox(es). Currently, the code enables user to toggle True/False value and change the csv file from just clicking on the cell, but the data_editor doesn't refresh itself. How do I solve this? Screenshot 2024-03-01 at 9 41 10 PM

Expected Behavior: the data_editor to render changes from csv file in real time.

Specifics: Python: 3.11.7 (Windows) Reflex version: 0.4.2 Browser: Chrome

tien-tran0906 avatar Mar 02 '24 05:03 tien-tran0906

Its should automatically update based on your state changes. May be a bug we will investigate more.

Alek99 avatar Mar 06 '24 18:03 Alek99

Hi @tien-tran0906 , I just tested your code. Can you give more clarity on what you mean by the data editor refreshing itself? It looks to me that DataEditorSelectOption.data calls get_data_list (a function out of the state.) which stores data from the csv file. Also looks like the DataEditorSelectOption.click_cell event handler writes to the the csv file. If your goal is to have the csv file loaded into DataEditorSelectOption.data everytime the cell is clicked, then consider having DataEditorSelectOption.data as a computed var, that way, the file is always loaded before displayed in the data editor:

class DataEditorSelectOption(rx.State):
    df = './site_csv_files/TEST3.csv'
     
    @rx.var
    def data(self) -> list[list[str]]
        return get_data_list(self.df)

Also a pro-tip: If your goal is to only render changes in the data editor when a cell is clicked, you don't necessarily have to write back into the csv file since DataEditorSelectOption.data( data = get_data_list) already contains data loaded from the csv. You can consider modifying data instead to save I/O read/write time

ElijahAhianyo avatar Apr 03 '24 14:04 ElijahAhianyo