Feedback streamlit with cassandra drivers

I query cassandra database, and Iโ€™m able to get data with 33 millions rows fastly,
https://docs.datastax.com/en/developer/python-driver/3.23/getting_started/

streamlit :yellow_heart:

1 Like

Thanks for sharing @NotAfk! Donโ€™t think weโ€™ve had anyone let us know about a Streamlit app using Cassandra.

Is this something you can share, or is this private/work-related?

# import library

import cassandra
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

# Connection to cassandra database

auth_provider = PlainTextAuthProvider(
username='username', password='password')
cluster = Cluster(['srv-spotfire'], auth_provider=auth_provider)
session = cluster.connect() 

# Query Cassandra

if (launch) and (end_date > start_date):
tic = time()
rowsTag = session.execute("SELECT name, timestamp, value FROM cluster.table WHERE name in "+str(tuple(tag_select))+"  and year in "+str(tuple(year_range))+" and timestamp >= $$"+str(start_date)+"$$ and timestamp <= $$"+str(end_date)+"$$;")

toc = time()
total =  toc - tic
     
taglist = []
for row in rowsTag :
  lister = [row.name, row.timestamp, row.value]
  taglist.append(lister)

if len(taglist) != 0:
  tag_df = pd.DataFrame(taglist)

1 Like

After that, data will be exported into csv file,
and I use Spotfire to open large .csv file.

But I have a bug to report => I donโ€™t know if this is related to the power of the machine / web navigator. When I use st.markdown() to make a download link for large data file, a blank page appear.(no shutdown of streamlit). I use this function to generate an download link.

def get_table_download_link(df):
โ€œโ€โ€œGenerates a link allowing the data in a given panda dataframe to be downloaded
in: dataframe
out: href string
โ€œโ€โ€
csv = df.to_csv(index = False, sep =โ€œ;โ€, encoding = โ€œlatin-1โ€, chunksize = 15000000)
b64 = base64.b64encode(csv.encode()).decode() # some strings โ†” bytes conversions necessary here

return f'<a href="data:file/csv;base64,{b64}" download="data.csv">Download csv file</a>'

How large is โ€œlargeโ€ in your case?

1 Like

I will give you an answer with more detail when I get back to office

1 Like
streamlit==0.58.0
CentOS Linux release 7.7.1908 (Core)
Web navigator = Google chrome Version 83.0.4103.106 (Build officiel) (64 bits)

:no_entry: : Blank page appear
:heavy_check_mark: : Nothing to report

  • 163 Mo :no_entry:
  • 81,5 Mo :no_entry:
  • 40,7 Mo :no_entry:
  • 39,1 Mo :no_entry:
  • 35,8 Mo :no_entry:
  • 34,2 Mo :heavy_check_mark:
  • 32,6 Mo :heavy_check_mark:
  • 24,4 Mo :heavy_check_mark:
  • 16,3 Mo :heavy_check_mark:
  • 1,62 Mo :heavy_check_mark:

Edit 1 : same behaviour in Microsoft Edge

The thing about creating a download link by passing the bytes is that it actually puts those bytes into the webpage. This is fine for a small amount of data, but at larger amounts, it probably does something weird to the browser (i.e. no one is expecting a 10GB webpage).

A proper file download solution is on our roadmap, but as of right now, I donโ€™t know the timing of that feature.

1 Like