$ pipenv install streamlit $ pipenv shell $ streamlit hello Welcome to Streamlit. Check out our demo in your browser. Local URL: http://localhost:8502 Network URL: http://5.179.250.48:8502
import streamlit as st
import numpy as np
import pandas as pd
st.title('My first app')
st.write("Using data to create a table:")
st.write(pd.DataFrame({
'first column': [1, 2, 3, 4],
'second column': [10, 20, 30, 40]
}))
df = pd.DataFrame({
'first column': [1, 2, 3, 4],
'second column': [10, 20, 30, 40]
})
df
chart_data = pd.DataFrame(
np.random.randn(20, 3),
columns=['a', 'b', 'c'])
st.line_chart(chart_data)
$ streamlit run test_app.py
# showing geographical map
st.map()
# Markdown text if checkbox activated
if st.checkbox("Click me"):
st.markdown("# Header")
# a unique select box in the sidebar
option = st.sidebar.selectbox("Select number", [1,2,3], key="unique")
"You selected", option
# using columns and buttons
left_column, right_column = st.beta_columns(2)
pressed = left_column.button('Press me?')
if pressed:
right_column.write("Woohoo!")
# changing order of appearance
slot_1 = st.empty()
st.text("This will appear last")
slot_1.text("This will appear first")
df = pd.DataFrame() # IDE says: "Statement seems to have no effect" # but generates a table view of the dataframe df # it is not possible to center the content, yet st.write(df.describe()) # By default info() does only return None # So we need some workaround to see the output buf = io.StringIO() df.info(buf=buf, verbose=True) st.text(buf.getvalue()) # we can use matplotlib and even seaborn plots # set_theme will globally change the layout of matplotlib plots import seaborne as sns sns.set_theme() st.pyplot(sns.relplot(data=dax, kind="line")) # Select the property ".figure" from the pandas inbuilt plotting st.pyplot(df.plot().figure) # hist returns a numpy array of subplots # we need to select the first one hist = df.hist(bins=100) st.pyplot(hist[0, 0].figure)
Plotly Dash | Streamlit | |
---|---|---|
focus | production | prototyping |
code | verbose | minimal |
aesthetics | ugly, but fully customisable | beautiful, but fixed |
interactivity | callbacks | linear |
performance | high | low |
caching | serious caching with redis, etc.. | only @st.cache |
plotting | plotly dash | streamlit, matplotlib, bokeh, altair, vega lite, pydeck, graphviz, plotly dash, ... |
deployment | Heroku (free), Dash Enterprise | Github (free), Streamlit for Teams |
authentication/security | yes | what is that? |
testing | yes, pytest fixtures | lalalalala |
see also medium.com: Plotly Dash vs Streamlit
jupyter notebooks < streamlit < plotly dash
Maybe we will finally see
something similar to
https://demonstrations.wolfram.com ,
but this time open source
and based on
Streamlit and Python
???