pandas 如何在streamlit中每3分钟刷新一次数据

fzsnzjdm  于 2022-12-09  发布在  其他
关注(0)|答案(1)|浏览(1066)

我写了这些函数来显示csv文件数据到用户界面的streamlit。该csv文件是在'w+'模式,所以数据得到刷新,以每3分钟,希望显示相同的用户界面。希望反映数据在同一时间的用户界面。该csv文件的数据得到更新的时间一样,9:15,9:18,9:21上午。

def strike_details():
    col1, col2 = st.columns(2)
    with col1:
        st.header("NIFTY")
        data1 = pd.read_csv(os.path.join(directory_of_python_script, str('strike_data_csv') , "NIFTY_strike.csv"), on_bad_lines='skip')
        st.table(data1)

    with col2:
        st.header("BANKNIFTY")
        data2 = pd.read_csv(os.path.join(directory_of_python_script, str('strike_data_csv') , "BANKNIFTY_strike.csv"), on_bad_lines='skip')
        st.table(data2)

strike_details()

此函数显示如下表

yjghlzjz

yjghlzjz1#

您是否尝试了schedule模块?

import time
import streamlit as st
from schedule import every, repeat, run_pending

with st.empty():
    @repeat(every(3).minutes)
    def strike_details():
        col1, col2 = st.columns(2)
        with col1:
            st.header("NIFTY")
            data1 = pd.read_csv(os.path.join(directory_of_python_script, str('strike_data_csv') , "NIFTY_strike.csv"), on_bad_lines='skip')
            st.table(data1)

        with col2:
            st.header("BANKNIFTY")
            data2 = pd.read_csv(os.path.join(directory_of_python_script, str('strike_data_csv') , "BANKNIFTY_strike.csv"), on_bad_lines='skip')
            st.table(data2)

    while True:
      run_pending()
      time.sleep(1)

相关问题