-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_withmenu.py
75 lines (54 loc) · 1.56 KB
/
app_withmenu.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Import Libraries
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import datetime
# Read CSV file
df = pd.read_csv("covid19pt_data.csv")
## set the index as the data column
## all of the remaining columns are now of the same int64 type
df = df.set_index('data')
# assign colors to column using a dictionary
# colors = dict('casos_novos_t':'coral',
# 'casos_novos_d':'darkviolet')
# Assing the chart to a variable
fig = go.Figure()
#set up ONE trace
fig.add_trace(go.Bar(x=df.index,
y=df[df.columns[0]],
# marker_color = colors,
visible=True))
updatemenu = []
buttons = []
# button with one option for each column
for col in df.columns:
buttons.append(dict(method='restyle',
label=col,
visible=True,
args=[{'y':[df[col]],
'x':[df.index],
'type':'bar'}, [0]],
)
)
# adjustments to the updatemenus
updatemenu = []
main_menu = dict()
updatemenu.append(main_menu)
updatemenu[0]['buttons'] = buttons
updatemenu[0]['direction'] = 'down'
updatemenu[0]['showactive'] = True
# add dropdown menus to the figure
fig.update_layout(showlegend=False, updatemenus=updatemenu)
fig.update_layout(
template='plotly_dark',
margin=dict(r=10, t=25, b=40, l=60)
)
def customLegend(fig, nameSwap):
for i, dat in enumerate(fig.data):
for elem in dat:
if elem == 'name':
fig.data[i].name = nameSwap[fig.data[i].name]
return(fig)
fig = customLegend(fig=fig, nameSwap = {'casos_novos_t': 'Novos Casos Total', 'casos_novos_d':'Novos Casos Diários'})
# Show Graphics
fig.show()