ndrezner commited on
Commit
a3177ba
·
1 Parent(s): 14fb3d0

Add Dash app template

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +41 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12
2
+ COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv
3
+
4
+ RUN useradd -m -u 1000 user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+ ENV UV_SYSTEM_PYTHON=1
7
+
8
+ WORKDIR /app
9
+
10
+ COPY --chown=user ./requirements.txt requirements.txt
11
+ RUN uv pip install -r requirements.txt
12
+
13
+ COPY --chown=user . /app
14
+ USER user
15
+
16
+ CMD ["gunicorn", "app:server", "--workers", "4", "--bind", "0.0.0.0:7860"]
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dash import Dash, dcc, callback, Output, Input
2
+ import plotly.express as px
3
+ import pandas as pd
4
+
5
+ df = pd.read_csv(
6
+ "https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv"
7
+ )
8
+
9
+ app = Dash()
10
+
11
+ server = app.server
12
+
13
+ app.layout = [
14
+ dcc.Markdown("""
15
+ # Welcome to Plotly Dash!
16
+
17
+ With Dash Open Source, you can create data apps on your laptop in pure Python,
18
+ no JavaScript required.
19
+
20
+ Get familiar with Dash by building a [sample app](https://dash.plotly.com/tutorial)
21
+ with open source. Scale up with [Dash Enterprise](https://plotly.com/dash/) when
22
+ your Dash app is ready for department or company-wide consumption. Or, launch your
23
+ initiative with Dash Enterprise from the start to unlock developer productivity
24
+ gains and hands-on acceleration from Plotly's team.
25
+
26
+ Try out this Dash app by changing the dropdown value, or get started with Dash on
27
+ HuggingFace by using this app [as a template](http://huggingface.co/new-space?template=plotly/dash-app-template).
28
+ """),
29
+ dcc.Dropdown(df.country.unique(), "Canada", id="dropdown-selection"),
30
+ dcc.Graph(id="graph-content"),
31
+ ]
32
+
33
+
34
+ @callback(Output("graph-content", "figure"), Input("dropdown-selection", "value"))
35
+ def update_graph(value):
36
+ dff = df[df.country == value]
37
+ return px.line(dff, x="year", y="pop")
38
+
39
+
40
+ if __name__ == "__main__":
41
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ dash
2
+ gunicorn
3
+ pandas