Page Renders Before Load

I am loading data from my database with a simple SQL query.
The data is quite large, so it takes a bit of time.
However, what’s happening is that the page is rendering before the data is loaded!
So it spits out a TypeError. I then play around with the GUI a bit (just changing states), and all of a sudden the table will be populated. However, if I don’t play with the GUI, it will remain in a TypeError screen.

Any thoughts as to why this is happening?

Hi @landmann

Could you provide a reproducible example for us to look at? Obviously, we don’t need the database credentials or even the query, just enough so we can see what the order of your Streamlit calls are.

Best,
Randy

1 Like

Thanks Randy,
It’s very straight forward… I’m using embeddings to embed a sentence and displaying the classification on the portal. Something like this:

import pandas as pd
import streamlit as st
import predict
from pytorch_pretrained_bert.modeling import BertForSequenceClassification

model = (BertForSequenceClassification.from_pretrained(PRETRAINED_PATH, 
                            num_labels=3, cache_dir=None))
cnn_headlines = pd.read_csv('headlines.csv')
cnn_headlines.set_index('timestamp', inplace=True)
cnn_headlines['sentiment'] = [predict(x, model) for x in cnn_headlines['headlines']]
st.table(cnn_headlines)

For some reason, it is only when I play with the sliders or touch the interface that the table fully loads, and then the sentiments load.