forked from tylerjrichards/Streamlit-for-Data-Science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigquery_app.py
31 lines (22 loc) · 844 Bytes
/
bigquery_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from google.cloud import bigquery
from google.oauth2 import service_account
from queries import get_streamlit_pypi_data
@st.cache_resource
def get_bigquery_client():
credentials = service_account.Credentials.from_service_account_info(
st.secrets["bigquery_service_account"]
)
return bigquery.Client(credentials=credentials)
client = get_bigquery_client()
@st.cache_data
def get_dataframe_from_sql(query):
df = client.query(query).to_dataframe()
return df
st.title("BigQuery App")
days_lookback = st.slider(
"How many days of data do you want to see?", min_value=1, max_value=30, value=5
)
pypi_query = get_streamlit_pypi_data(days_lookback)
downloads_df = get_dataframe_from_sql(pypi_query)
st.line_chart(downloads_df, x="file_downloads_timestamp_date", y="file_downloads_count")