Py.Cafe

evilqoodotcom/

dash-data-analysis

Data Analysis with Dash

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.express as px

# Initialize the Dash app
app = dash.Dash(__name__)

# Define the app layout
app.layout = html.Div([
    dcc.Upload(
        id='upload-data',
        children=html.Div([
            'Drag and Drop or ',
            html.A('Select Files')
        ]),
        style={
            'width': '100%',
            'height': '60px',
            'lineHeight': '60px',
            'borderWidth': '1px',
            'borderStyle': 'dashed',
            'borderRadius': '5px',
            'textAlign': 'center',
            'margin': '10px'
        },
        multiple=False
    ),
    dcc.Graph(id='graph')
])

# Define the callback to process the uploaded file and create the graph
@app.callback(
    Output('graph', 'figure'),
    Input('upload-data', 'contents')
)
def update_graph(contents):
    if contents is not None:
        content_type, content_string = contents.split(',')

        decoded = base64.b64decode(content_string)
        df = pd.read_excel(io.BytesIO(decoded))

        fig = px.scatter(df, x="x_column", y="y_column")  # Replace with your desired plot type and columns

        return fig

if __name__ == '__main__':
    app.run_server(debug=True)