Py.Cafe

banana0000/

dash-data-visualization-explorer

Dash Data Visualization Explorer

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
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px

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

# Create data for the plots
df = px.data.iris()

# Layout of the app
app.layout = html.Div([
    dcc.Location(id='url', refresh=False),  # Listening to URL changes
    html.Div([
        html.Nav([
            html.Ul([
                html.Li(dcc.Link('Page 1', href='/')),
                html.Li(dcc.Link('Page 2', href='/page2')),
            ])
        ]),
    ]),
    html.Div(id='page-content')  # Content will be displayed here
])

# Display the content of Page 1
@app.callback(
    Output('page-content', 'children'),
    Input('url', 'pathname')
)
def display_page(pathname):
    if pathname == '/page2':
        fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
        return html.Div([
            html.H1('Page 2 - Scatter plot'),
            dcc.Graph(figure=fig)
        ])
    # Default page (Page 1)
    fig = px.line(df, x="sepal_width", y="sepal_length", color="species")
    return html.Div([
        html.H1('Page 1 - Line plot'),
        dcc.Graph(figure=fig)
    ])

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