Skip to content

Instantly share code, notes, and snippets.

@quintonwall
Created October 3, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quintonwall/906f4be0c8ebe8441916b262ac5e704e to your computer and use it in GitHub Desktop.
Save quintonwall/906f4be0c8ebe8441916b262ac5e704e to your computer and use it in GitHub Desktop.
import streamlit as st
import os
import pandas
import requests.exceptions
import logging
from thoughtspot import ThoughtSpot
# fetch from .env file
username = st.secrets["thoughtspot"]["ts_username"]
password = st.secrets["thoughtspot"]["ts_password"]
server = st.secrets["thoughtspot"]["ts_server"]
logging.info(server)
# Auth with ThoughtSpot
ts: ThoughtSpot = ThoughtSpot(server_url=server)
try:
ts.login(username=username, password=password)
logging.info("logged into thoughtspot. Hello "+username)
except requests.exceptions.HTTPError as e:
print(e)
print(e.response.content)
# search ThoughtSpot
def fetchdata():
data = ts.tsrest.searchdata(query_string="[sales] [region]", data_source_guid="cd252e5c-b552-49a8-821d-3eadaa049cca")
dframe = pandas.DataFrame(columns=data['columnNames'],data=data['data'])
dframe = pandas.to_numeric(dframe['Total sales'])
st.bar_chart(data=dframe, width=500, height=500, use_container_width=True)
#The page
st.title('ThoughtSpot + Streamlit: ')
st.button(label="Search ThoughtSpot", on_click=fetchdata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment