Skip to content

Instantly share code, notes, and snippets.

@hbshrestha
Last active May 21, 2021 16:27
Show Gist options
  • Save hbshrestha/3d5461485b3cd0b74ff09597d693330d to your computer and use it in GitHub Desktop.
Save hbshrestha/3d5461485b3cd0b74ff09597d693330d to your computer and use it in GitHub Desktop.
dropdowns = [] #Initialize as an empty list
i = 0 #Intialize a counter
#Iterate through df_dict
for key,value in df_dict.items():
#add a bar trace to the figure for each indicator
fig.add_trace(go.Bar(name=key,
x=value.iloc[:,0], #x is the squad name
y=value.iloc[:,1], #y is the value for each indicator
visible= (i==0), #Set only the indicator corresponding to i to be visible as default
marker_color="blue" #Color of the bars
)
)
#args is a list of booleans that tells the buttons which trace to show on click
args = [False] * len(df_dict)
args[i] = True
#create a button object for the corresponding indicator
dropdown = dict(label = key,
method = "update",
args=[{"visible": args}])
#add the button to our list of buttons
dropdowns.append(dropdown)
#i is an iterable used to tell our "args" list which value to set to True
i+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment