수정

Published onesixx on

    
    @reactive.calc
    @render.text
    async def csv_processing():
        file: list[FileInfo] | None = input.csv()
        if file is None:
            return None
        
        with ui.Progress(min=1, max=100) as _p:
            _p.set(message="Progressing...", detail="This may take a while...")
            _p.set(30, message="file uploading...")      
            csv_nm = file[0]["name"]  # dict_keys(['name', 'size', 'type', 'datapath'])
            csv_datapath = file[0]["datapath"]
            # db_file_nm = csv_nm(".",0)+".db"
            # db_file = DATA_DIR.joinpath("db", db_file_nm)
            _p.set(60, message="file uploaded successfully!")
            db_file = DATA_DIR.joinpath("db", "csv.db")
            conn = duckdb.connect(str(db_file), read_only=False)
            conn.execute(f"""
                CREATE TABLE '{csv_nm}' AS SELECT * FROM read_csv_auto('{csv_datapath}')
            """)
            conn.close()
            _p.set(100, message="Done Processing!")
        return "Done Processing!"

fix

    @reactive.calc
    def parse_file():
        file: list[FileInfo] | None = input.db_file_csv()
        req(file is not None, "Please upload a file") 
        
        with ui.Progress(min=1, max=100) as _p:
            _p.set(message="Progressing...", detail="This may take a while...")
            _p.set(30, message="file uploading...")      
            csv_nm = os.path.splitext(file[0]["name"])[0] # dict_keys(['name', 'size', 'type', 'datapath'])
            csv_datapath = file[0]["datapath"]
            # db_file_nm = csv_nm(".",0)+".db"
            # db_file = DATA_DIR.joinpath("db", db_file_nm)
            _p.set(60, message="file uploaded successfully!")
            db_file = DATA_DIR.joinpath("db", "csv.db")
            conn = duckdb.connect(str(db_file), read_only=False)
            conn.execute(f"""
                CREATE TABLE '{csv_nm}' AS SELECT * FROM read_csv_auto('{csv_datapath}')
            """)
            # table = table.replace("NA", np.nan)
            conn.close()
            _p.set(100, message="Done Processing!")
        return "Done Processing!"

    @output
    @render.text
    def db_txt_csvResult():
        result = parse_file()
        logger.info(f"db_txt_csvResult: {result}")
        req(result is not None)
        return result
Categories: shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x