How to connect Streamlit with GCP - YC-1412/CISC525_final_project GitHub Wiki
Most information from - Connect Streamlit to Google Cloud Storage
Create a service role for viewing data
Modify the code
-
Save the json file in a toml file and format instead. Will use it later.
-
pip install st_files_connection
-
In the code
from st_files_connection import FilesConnection
Use conn.fs to access the underlying FileSystem object API. (https://github.com/streamlit/files-connection)
conn = st.connection("gcs", type=FilesConnection) fs = conn.fs # Get the underlying fsspec filesystem covid_files = fs.glob(f'gs://{BUCKET_NAME}/final_project/data/processed_data/covid_*_all.csv') covid_files_US = fs.glob(f'gs://{BUCKET_NAME}/final_project/data/processed_data/covid_*_US.csv') flight_files = fs.glob(f'gs://{BUCKET_NAME}/final_project/data/processed_data/flight_*_US.csv') df_covid_month = pd.concat([pd.read_csv(fs.open(file)) for file in covid_files], ignore_index=True)
Refer to the code for examples: https://github.com/YC-1412/CISC525_final_project/blob/25612ce9b979c7938cf40ac21f32cde942848823/deployment/src/streamlit_app_V2_1.py#L20-L48
Deploy
-
Paste the URL to the streamlit.py file
-
Copy the info from toml file here. Any environment variables are saved there as well as below.
-
Done!