-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard-example.py
More file actions
59 lines (50 loc) · 1.37 KB
/
dashboard-example.py
File metadata and controls
59 lines (50 loc) · 1.37 KB
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
52
53
54
55
56
57
58
59
#%%
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import pandas as pd
from dash.dependencies import Input, Output
# Crie uma aplicação Dash
app = dash.Dash(__name__)
# Gerando dados aleatórios
np.random.seed(42)
dates = pd.date_range(start="2024-01-01", periods=100)
values = np.random.randn(100).cumsum()
# DataFrame com os dados
df = pd.DataFrame({"Date": dates, "Value": values})
# Layout do dashboard
app.layout = html.Div([
html.H1("Dashboard Simples com Dash"),
dcc.Graph(id="line-chart"),
dcc.Slider(
id="date-slider",
min=0,
max=len(df) - 1,
value=len(df) - 1,
marks={i: str(date.date()) for i, date in enumerate(df['Date'])},
step=None
)
])
# Callback para atualizar o gráfico
@app.callback(
Output("line-chart", "figure"),
[Input("date-slider", "value")]
)
def update_chart(selected_date_index):
filtered_df = df.iloc[:selected_date_index + 1]
return {
"data": [{
"x": filtered_df["Date"],
"y": filtered_df["Value"],
"type": "line"
}],
"layout": {
"title": "Gráfico de Linha",
"xaxis": {"title": "Data"},
"yaxis": {"title": "Valor"},
}
}
# Executando a aplicação
if __name__ == "__main__":
app.run_server(debug=True)