Automate a schedule task at streamlit

Viewed 540

I currently have a deployed application at heroku that uses streamlit framework for data analysis. However the page opens very slow since every time a user opens the website, it starts to download a CSV data.

So, my goal is to atomate a task to download the CSV data to make the website lightweight. Is there any way to use for example, schedule library into streamlit to download the CSV data daily?

1 Answers

I don't think there is a solution using only Streamlit.

I had the same problem and managed to get it fixed by creating another script to run via a cron.

Your script:

# create a python script that will download the 
# csv data
# bear in mind, what I write is an example, 
# since it is a Python script, you can do whatever you want ;)

def create_csv():
    with open("/path/to/csv", "w") as f:
        f.write("a,b,c\n1,2,3")


if __name__ == "__main__":
    create_csv()

And you make this script run every hour (for example):

crontab -e

Inside the opened file:

0 * * * *  cd /path/to/script && python script.py

You can check the cron syntax here.

Related