llepogam commited on
Commit
68b5923
Β·
1 Parent(s): 40dc3e2

Add application file

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. app.py +163 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM continuumio/miniconda3
2
+
3
+ WORKDIR /home/app
4
+
5
+ RUN apt-get update
6
+ RUN apt-get install nano unzip
7
+ RUN apt install curl -y
8
+
9
+ RUN curl -fsSL https://get.deta.dev/cli.sh | sh
10
+ RUN pip install boto3 pandas gunicorn streamlit scikit-learn matplotlib seaborn plotly
11
+ COPY . /home/app
12
+
13
+
14
+
15
+ CMD ["streamlit", "run", "app.py", "--server.port", "$PORT", "--server.address", "0.0.0.0"]
app.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+ import numpy as np
6
+
7
+ ### Config
8
+ st.set_page_config(
9
+ page_title="E-commerce",
10
+ page_icon="πŸ’Έ ",
11
+ layout="wide"
12
+ )
13
+
14
+ DATA_URL = ('https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/e-commerce_data.csv')
15
+
16
+ ### App
17
+ st.title("Build dashboards with Streamlit 🎨")
18
+
19
+ st.markdown("""
20
+ Welcome to this awesome `streamlit` dashboard. This library is great to build very fast and
21
+ intuitive charts and application running on the web. Here is a showcase of what you can do with
22
+ it. Our data comes from an e-commerce website that simply displays samples of customer sales. Let's check it out.
23
+
24
+ You can download the whole code here πŸ‘‰ [Source code](https://github.com/JedhaBootcamp/streamlit-demo-app)
25
+
26
+ Also, if you want to have a real quick overview of what streamlit is all about, feel free to watch the below video πŸ‘‡
27
+ """)
28
+
29
+ with st.expander("⏯️ Watch this 15min tutorial"):
30
+ st.video("https://youtu.be/B2iAodr0fOo")
31
+
32
+ st.markdown("---")
33
+
34
+
35
+ # Use `st.cache` when loading data is extremly useful
36
+ # because it will cache your data so that your app
37
+ # won't have to reload it each time you refresh your app
38
+ @st.cache
39
+ def load_data(nrows):
40
+ data = pd.read_csv(DATA_URL, nrows=nrows)
41
+ data["Date"] = data["Date"].apply(lambda x: pd.to_datetime(",".join(x.split(",")[-2:])))
42
+ data["currency"] = data["currency"].apply(lambda x: pd.to_numeric(x[1:]))
43
+ return data
44
+
45
+ st.subheader("Load and showcase data")
46
+ st.markdown("""
47
+
48
+ You can use the usual Data Science libraries like `pandas` or `numpy` to load data.
49
+ Then simply use [`st.write()`](https://docs.streamlit.io/library/api-reference/write-magic/st.write) to showcase it on your web app.
50
+
51
+ """)
52
+
53
+ data_load_state = st.text('Loading data...')
54
+ data = load_data(1000)
55
+ data_load_state.text("") # change text from "Loading data..." to "" once the the load_data function has run
56
+
57
+ ## Run the below code if the check is checked βœ…
58
+ if st.checkbox('Show raw data'):
59
+ st.subheader('Raw data')
60
+ st.write(data)
61
+
62
+ ## Simple bar chart
63
+ st.subheader("Simple bar chart built directly with Streamlit")
64
+ st.markdown("""
65
+ You can build simple chart directly with streamlit using:
66
+
67
+ * [`st.bar_chart`](https://docs.streamlit.io/library/api-reference/charts/st.bar_chart)
68
+ * [`st.line_chart`](https://docs.streamlit.io/library/api-reference/charts/st.line_chart)
69
+ * [`st.area_chart`](https://docs.streamlit.io/library/api-reference/charts/st.area_chart)
70
+
71
+ Eventhough it doesn't offer great flexibility, it is still a very simple way to create graphs quickly since
72
+ streamlit since these methods accepts a pandas DataFrame or Numpy array as input.
73
+
74
+ """)
75
+ currency_per_country = data.set_index("country")["currency"]
76
+ st.bar_chart(currency_per_country)
77
+
78
+ ## Bar chart built with plotly
79
+ st.subheader("Simple bar chart built with Plotly")
80
+ st.markdown("""
81
+ Now, the best thing about `streamlit` is its compatibility with other libraries. For example, you
82
+ don't need to actually use built-in charts to create your dashboard, you can use :
83
+
84
+ * [`plotly`](https://docs.streamlit.io/library/api-reference/charts/st.plotly_chart)
85
+ * [`matplotlib`](https://docs.streamlit.io/library/api-reference/charts/st.pyplot)
86
+ * [`bokeh`](https://docs.streamlit.io/library/api-reference/charts/st.bokeh_chart)
87
+ * ...
88
+
89
+ This way, you have all the flexibility you need to build awesome dashboards. πŸ₯°
90
+
91
+ """)
92
+ fig = px.histogram(data.sort_values("country"), x="country", y="currency", barmode="group")
93
+ st.plotly_chart(fig, use_container_width=True)
94
+
95
+
96
+ ### Input data
97
+ st.subheader("Input data")
98
+ st.markdown("""
99
+ As a final note, you can use data that a user will insert when he/she interacts with your app.
100
+ This is called *input data*. To collect these, you can do two things:
101
+ * [Use any of the input widget](https://docs.streamlit.io/library/api-reference/widgets)
102
+ * [Build a form](https://docs.streamlit.io/library/api-reference/control-flow/st.form)
103
+
104
+ Depending on what you need to do, you will prefer one or the other. With a `form`, you actually group
105
+ input widgets together and send the data right away, which can be useful when you need to filter
106
+ by several variables.
107
+
108
+ """)
109
+
110
+ #### Create two columns
111
+ col1, col2 = st.columns(2)
112
+
113
+ with col1:
114
+ st.markdown("**1️⃣ Example of input widget**")
115
+ country = st.selectbox("Select a country you want to see all time sales", data["country"].sort_values().unique())
116
+
117
+ country_sales = data[data["country"]==country]
118
+ fig = px.histogram(country_sales, x="Date", y="currency")
119
+ fig.update_layout(bargap=0.2)
120
+ st.plotly_chart(fig, use_container_width=True)
121
+
122
+ with col2:
123
+ st.markdown("**2️⃣ Example of input form**")
124
+
125
+ with st.form("average_sales_per_country"):
126
+ country = st.selectbox("Select a country you want to see sales", data["country"].sort_values().unique())
127
+ start_period = st.date_input("Select a start date you want to see your metric")
128
+ end_period = st.date_input("Select an end date you want to see your metric")
129
+ submit = st.form_submit_button("submit")
130
+
131
+ if submit:
132
+ avg_period_country_sales = data[(data["country"]==country)]
133
+ start_period, end_period = pd.to_datetime(start_period), pd.to_datetime(end_period)
134
+ mask = (avg_period_country_sales["Date"] > start_period) & (avg_period_country_sales["Date"] < end_period)
135
+ avg_period_country_sales = avg_period_country_sales[mask].mean()
136
+ st.metric("Average sales during selected period (in $)", np.round(avg_period_country_sales, 2))
137
+
138
+
139
+ ### Side bar
140
+ st.sidebar.header("Build dashboards with Streamlit")
141
+ st.sidebar.markdown("""
142
+ * [Load and showcase data](#load-and-showcase-data)
143
+ * [Charts directly built with Streamlit](#simple-bar-chart-built-directly-with-streamlit)
144
+ * [Charts built with Plotly](#simple-bar-chart-built-with-plotly)
145
+ * [Input Data](#input-data)
146
+ """)
147
+ e = st.sidebar.empty()
148
+ e.write("")
149
+ st.sidebar.write("Made with πŸ’– by [Jedha](https://jedha.co)")
150
+
151
+
152
+
153
+ ### Footer
154
+ empty_space, footer = st.columns([1, 2])
155
+
156
+ with empty_space:
157
+ st.write("")
158
+
159
+ with footer:
160
+ st.markdown("""
161
+ πŸ‡
162
+ If you want to learn more, check out [streamlit's documentation](https://docs.streamlit.io/) πŸ“–
163
+ """)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn