# A first view on Streamlit¶

I had a look into streamlit as anoter way to deploy a data science app. It seems really convenient to work with.

Unfortunately, I cannot use it on a static website, so I need to learn how to deploy it on a service with Docker.

## Tutorial¶

I went through the getting started tutorial, below are the main steps.

We import streamlit as a separate package and simply run it in as script.

streamlit run first_app.py


This, by default, creates a local server where we can see the results.

In [1]:
import streamlit as st

import numpy as np
import pandas as pd
import altair as alt


Streamlit tries to diplay everything, somehow similar how it happens in a jupyter notebook.

In [2]:
df = pd.DataFrame({"first": [1, 2, 3, 4], "second": [10, 20, 30, 40]})

df

Out[2]:
first second
0 1 10
1 2 20
2 3 30
3 4 40

In [3]:
chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])

st.line_chart(chart_data)

Out[3]:
&lt;streamlit.delta_generator.DeltaGenerator at 0x7fd5941fdc70&gt;

In [4]:
map_data = pd.DataFrame(
np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"]
)

st.map(map_data)

Out[4]:
&lt;streamlit.delta_generator.DeltaGenerator at 0x7fd5941fdc70&gt;

In [5]:
if st.checkbox('Show dataframe'):
chart_data = pd.DataFrame(np.random.randn(20, 3), columns = ['a', 'b', 'c'])

st.line_chart(chart_data)

option = st.sidebar.selectbox("Which number do you like best?", df['first'])

'You selected ', df.loc[df['first'] == option, :]

Out[5]:
(&#39;You selected &#39;,
first  second
0      1      10)

In [6]:
import time

"Long computation..."


&#39;...and done!&#39;