Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dash import Dash, html, dcc
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Initialize the Dash app
|
| 7 |
+
app = Dash(__name__)
|
| 8 |
+
server = app.server # This is important for deployment
|
| 9 |
+
|
| 10 |
+
# Create the data frame
|
| 11 |
+
df = pd.DataFrame({
|
| 12 |
+
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
|
| 13 |
+
"Amount": [4, 1, 2, 2, 4, 5],
|
| 14 |
+
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
# Create the figure
|
| 18 |
+
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
|
| 19 |
+
|
| 20 |
+
# Define the app layout
|
| 21 |
+
app.layout = html.Div(children=[
|
| 22 |
+
html.H1(children='Hello Dash'),
|
| 23 |
+
html.Div(children='''
|
| 24 |
+
Dash: A web application framework for your data.
|
| 25 |
+
'''),
|
| 26 |
+
dcc.Graph(
|
| 27 |
+
id='example-graph',
|
| 28 |
+
figure=fig
|
| 29 |
+
)
|
| 30 |
+
])
|
| 31 |
+
|
| 32 |
+
if __name__ == '__main__':
|
| 33 |
+
# For local development
|
| 34 |
+
app.run_server(debug=True)
|
| 35 |
+
else:
|
| 36 |
+
# For deployment (Hugging Face Spaces will use this)
|
| 37 |
+
server = app.server
|