Streamlit line chart doesn't recognize number field in Google sheet

Ask the community or our support engineers for answers to questions.

Dear everyone, why does streamlit not recognize the field name of 2022 in Google Sheet? I would attach the code as well. Thank You!

import streamlit as st
from gsheetsdb import connect
import itertools

import streamlit as st
from vega_datasets import data
import pandas as pd
import numpy as np


# Create a connection object.
conn = connect()

# Perform SQL query on the Google Sheet.
# Uses st.cache to only rerun when the query changes or after 10 min.
@st.cache(ttl=600)
def run_query(query):
    rows = conn.execute(query, headers=1)
    rows = rows.fetchall()
    return rows

sheet_url = st.secrets["public_gsheets_url"]
rows = run_query(f'SELECT * FROM "{sheet_url}"')

st.line_chart(rows, x="Date", y=["2022","Alarm","Flood"])

Two quick things:

  1. It’s recommended to switch from using st.cache to st.experimental_memo
  2. Can you try printing out your data before plotting it (i.e. st.write(rows)), in order to make sure it has all the columns that you expect?
1 Like

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