Google Docs and Streamlit

Summary

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 = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("your-credentials.json", scope)
client = gspread.authorize(creds)

# Access the Google Sheet
sheet_url = "https://docs.google.com/spreadsheets/d/1OBEMIUloci4WV80D-yLhhoLMVQymy-TYlh7jwGXmND8/edit#gid=0"
worksheet = client.open_by_url(sheet_url).sheet1

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

# Display data in Streamlit
st.write(data)

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

Thank you for your support! :wink:
bye

Matt

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
st.table(df)

Is this what you are after?

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

import pandas as pd

Best,
Charly

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.