Hello! I’m dveloping my first streamlit dashboard.
I’ve tried to run it locally, but a problem occurs.
The secrets.toml file is correctly uploaded into the CWD/.streamlit folder and has the following form:
[gsheets]
spreadsheet = ""
[gsheets.credentials]
type = "service_account"
...
This is a sample code:
import streamlit as st
from gspread_pandas import Spread, Client
from google.oauth2 import service_account
import pandas as pd
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
# Load secrets
secrets = st.secrets["gsheets"]
print(secrets)
credentials = service_account.Credentials.from_service_account_info(
secrets["credentials"],
scopes=scope
)
client = Client(scope=scope, creds=credentials)
spreadsheetname = "weight"
spread = Spread(spreadsheetname, client=client)
# Check the connection
st.write(spread.url)
sh = client.open(spreadsheetname)
worksheet_list = sh.worksheets()
# Functions
@st.cache()
# Get our worksheet names
def worksheet_names():
sheet_names = []
for sheet in worksheet_list:
sheet_names.append(sheet.title)
return sheet_names
# Get the sheet as dataframe
def load_the_spreadsheet(name):
worksheet = sh.worksheet(name)
df = pd.DataFrame(worksheet.get_all_records())
return df
dataframe = load_the_spreadsheet(spreadsheetname)
st.dataframe(dataframe)
And the error in the browser is:
SpreadsheetNotFound: Spreadsheet not found
I’ve also noticed that when printing secrets the shell returns a dict and a “Couldn’t retrieve email. Delete credentials and authenticate again”