The possibilities with Streamlit library are infinite. Building a dashboard is probably the simplest thing you can dabble using this library.
You can find the end product over here on Heroku: https://faker-streamlit.herokuapp.com/
Importing the necessary libraries
import streamlit as st
import pandas as pd
from faker import Faker
import random
import plotly.express as px
from wordcloud import WordCloud, STOPWORDS
import base64
After generating 500 data points from the Faker library including latitude and longitude, it’s time to build our interactive dashboard.
Creating a histogram from plotly express
fig2 = px.histogram(data_country, x=’job’, y=’salary’, color=’sentiment’, facet_col=’country’, facet_row=’sex’, histfunc=’sum’, width=900, height=600) st.plotly_chart(fig2)
Creating points on world map
With lat and lon in the dataframe, you can now create quick geospatial scatterplots with just one line of code. If you need more control, you’ll need to use st.pydeck_chart
which I have not tried.
st.map(modified_data)
Creating a wordcloud
fig = px.imshow(wordcloud, width=700, height=700, x=None, y=None) fig.update_layout(
yaxis=dict(tickvals=[]),
xaxis=dict(tickvals=[])
) st.plotly_chart(fig)
Downloading the dataset
To display the dataframe on Streamlit, all it took was just one line of code. But I thought “Wouldn’t it be awesome if I could download the data onto my local computer?” It didn’t take me long to find a ready solution on Google.
### SHOW RAW DATA
if st.sidebar.checkbox('Show raw data',True): st.subheader('Showing raw data below')
st.write(data) with st.beta_expander("Expand to download data into CSV"): tmp_download_link = download_link(data, 'faker-data.csv', 'Click here to download your data!')
st.markdown(tmp_download_link, unsafe_allow_html=True)
Where to find the code
The code can be found over here: https://github.com/hxkoey/streamlit-example
Final Thoughts
Since I started coding about a year ago, I have been using Jupyter notebooks on my local computer which has been fantastic so far. As I progressed along this journey, I came to realise that there are times where I had to scour the Internet for the same piece of stackoverflow which can get a little bit frustrating.
So here I am, finally documenting my journey. Like what Gary Vee often preached, “Document. Don’t create.” 💌