Google Docs and Streamlit


Hi guys :smiley:,
I have a problem about the retrive of a shared Google Docs file from Google Drive and display the content of file on streamlit in a pretty way. Can you help me?

Steps to reproduce

Code snippet:

Example of my script:

import streamlit as st
import gspread
from oauth2client.service_account import ServiceAccountCredentials

# Set up Google API credentials
scope = ["", ""]
creds = ServiceAccountCredentials.from_json_keyfile_name("your-credentials.json", scope)
client = gspread.authorize(creds)

# Access the Google Sheet
sheet_url = ""
worksheet = client.open_by_url(sheet_url).sheet1

# Read data from the worksheet
data = worksheet.get_all_values()

# Display data in Streamlit

I expect to have the text of the document in streamlit to display in different way.

Thank you for your support! :wink:


Hey @M-ballabio1! :wave:

To make the output appear more polished in Streamlit, you might want to use Pandas and perhaps format the data in a table using st.table or st.dataframe. Here’s a simple example:

data = worksheet.get_all_values()
df = pd.DataFrame(data[1:], columns=data[0])

# Display data in Streamlit as a table

Is this what you are after?

Note: don’t forget to import Pandas in your Python file! :wink:

import pandas as pd