【发布时间】:2022-04-05 23:32:51
【问题描述】:
我目前在 heroku 部署了一个应用程序,它使用 streamlit 框架进行数据分析。但是页面打开速度很慢,因为每次用户打开网站时,它都会开始下载 CSV 数据。
所以,我的目标是分解下载 CSV 数据的任务,以使网站变得轻量级。有什么方法可以使用,例如,将库安排到 streamlit 中以每天下载 CSV 数据?
【问题讨论】:
标签: python heroku schedule streamlit
我目前在 heroku 部署了一个应用程序,它使用 streamlit 框架进行数据分析。但是页面打开速度很慢,因为每次用户打开网站时,它都会开始下载 CSV 数据。
所以,我的目标是分解下载 CSV 数据的任务,以使网站变得轻量级。有什么方法可以使用,例如,将库安排到 streamlit 中以每天下载 CSV 数据?
【问题讨论】:
标签: python heroku schedule streamlit
我认为没有只使用 Streamlit 的解决方案。
我遇到了同样的问题,并设法通过创建另一个脚本以通过 cron 运行来解决它。
你的脚本:
# 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()
你让这个脚本每小时运行一次(例如):
crontab -e
打开的文件里面:
0 * * * * cd /path/to/script && python script.py
您可以检查 cron 语法here。
【讨论】: