Tiger Graph + Streamlit → Dynamically Visualize South Korea COVID-19 Data

Rohan Shiva
5 min readMay 29, 2020

--

Getting started

Tiger graph is a super fast an intuitive graph database. In this article, we will grabbing data from a graph database and explore the data by using streamlit’s visualization tools.

Agenda

Setting up Tiger Graph

Connecting Tiger Graph and Python

Making a query to get some data

Intro to Streamlit

Using our query and Streamlit

Setting up Tiger Graph Account

Head over to tgcloud.io and login to your account, if you haven’t already make a new account. After you log in, navigate to “My Solutions” and create a solution.

In this article, we will use the COVID-19 Analysis starter kit to explore Tiger Graph and Streamlit. I will be setting up a basic free box with 50gb of storage. Next, name your solution, give your box a password, and a little description.

Setting up a box with COVID Starter Kit

Now it’s time to grab a coffee and wait for the box to be ready. After the solution is ready, click on the applications icon and head over to graph studio.

Graph Studio

This is your graph studio, you can design, load data, explore, and write queries here — it is awesome! If you want to learn more about this specific graph database, check out this amazing video by Jon Herke who created this graph. The video walks you through the setup process and explores the graph and queries. In this article, I will be focusing more on connecting the graph database with python.

Now that we have our graph ready, let’s connect the graph to python.

First, we need to install pyTigerGraph, a simple python library developed by Parker Erickson.

You can install pyTigerGraph by simply running this command

pip install pyTigerGraph

Now we need to grab some secret credentials from our Graph Studio. Head over to Admin — User Management and make a new secret. We will use this secret to create a token. The token is used to make calls to the built-in REST endpoints.

We can generate a token by running the following code block. Here we are using the functions from pyTigerGraph to make a connection. “host” is the domain of your graph studio, and replace the SECRET from the getToken with your custom secret. If you want to learn more about pyTigerGraph, check out Parker Erickson’s article on Intro to pyTigerGraph.

Now that we have our token and secret we can make a call to one of our endpoints to run a query. Let’s make a query to get the Age, Sex, Latitude, and Longitude of every patient from the South Korea COVID-19 dataset.

Intro to Streamlit

Streamlit is an open-source python library that allows you to build beautiful web apps to visualize anything (Machine Learning, Data, and Data Science). In this article, we will dive into the Streamlit, and explore some of the features that streamlit offers!

Installing and Setting up Streamlit

Installing streamlit is super simple

pip install streamlit

Creating an App

Now, create a file named app.py and import streamlit

import streamlit as st

Every good app has a title, so lets add one

st.title('Exploring Streamlit')

You can run the app by simply opening the terminal in the folder and running the following command. The FILENAME for us is app.py

streamlit run FILENAME
streamlit run app.py

The app will then run on your local machine and open in a browser!

Let’s make a simple addition calculator

st.write('## Add interactions using widgets!')
a = st.slider('Number 1')
b = st.slider('Number 2')
st.write('Answer is', a + b)

Streamlit automatically detects file changes and prompts you to rerun the app

Congratulations you have successfully built your first streamlit app!

Now let’s try something more fun. I am using the Titanic Dataset from Kaggle to explore some of streamlit features. I am using pandas to read the data. If you don’t already know about pandas, it is a super popular python library used for data analysis, and manipulation. You can learn more about it here https://pandas.pydata.org/.

import pandas as pd
import streamlit as st
st.title('Titanic Data Visualization')
data = pd.read_csv('data.csv') # Pandas reading the data file
st.write(data)

Now let’s add some widget’s to filter the data


sex = st.multiselect('Sex', ['male', 'female'])
if(len(sex)==1):
data = data[data.Sex==sex[0]]
st.write(data)

Using data from our query and Streamlit

Now that we know some basics of streamlit and TigerGraph, let’s use the query to visualize the South Korea COVID-19 data.

We are using Pandas and flat_table to clean up the data and get it ready for streamlit.

Streamlit is super customizable and you can use it with other great libraries like plotly, matplot, bokeh, and many others. Here is an example of using plotly widgets.

pip install plotly

Then you can use plotly like this …

import plotly.express as px
fig = px.line(age, x="attributes.Age")st.plotly_chart(fig)

Conclusion

As you can see, both TigerGraph and Streamlit are awesome, this is just the tip of the iceberg — and the possibilities are endless. There are many amazing apps built using streamlit like these — https://www.streamlit.io/gallery. I hope you learned something!

Special thanks to Jon Herke, Parker Erickson, Ramki Pitchala, and Akash Kaul for helping me write this blog. I hope you learned something and … bye!

--

--

No responses yet