-
-
Save quintonwall/906f4be0c8ebe8441916b262ac5e704e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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