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
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
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)
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 herereturn f'<a href="data:file/csv;base64,{b64}" download="data.csv">Download csv file</a>'
How large is “large” in your case?
I will give you an answer with more detail when I get back to office
streamlit==0.58.0
CentOS Linux release 7.7.1908 (Core)
Web navigator = Google chrome Version 83.0.4103.106 (Build officiel) (64 bits)
: Blank page appear
: Nothing to report
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.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.