none commited on
Commit
50cf0f6
1 Parent(s): 4a4f597

buttons working better

Browse files
Files changed (1) hide show
  1. streamlit_viz.py +16 -44
streamlit_viz.py CHANGED
@@ -188,12 +188,6 @@ def main():
188
  frames = [go.Frame(data=graph_obj) for graph_obj in graph_objs]
189
  # show them with streamlit
190
 
191
- # this puts them all on the screen at once
192
- # like each new one shows up below the previous one
193
- # instead of replacing the previous one
194
- #for fig in figures:
195
- # st.plotly_chart(fig)
196
- # time.sleep(1)
197
 
198
  # This works the way I want
199
  # but the plot is tiny
@@ -229,47 +223,28 @@ def main():
229
  # this one finally set the speed
230
  # no mention of how they figured this out but thank goodness I found it
231
  # https://towardsdatascience.com/basic-animation-with-matplotlib-and-plotly-5eef4ad6c5aa
 
 
 
232
  ani_fig = go.Figure(
233
  data=graph_objs[0],
234
  frames=frames,
235
  layout=go.Layout(
236
  updatemenus=[{
237
  'type':'buttons',
238
- # Streamlit's dark mode erases the text from this button
239
- # but it shows up in light mode
240
- # also, st.button() buttons show up fine in dark mode
241
-
242
- # Trying some of these to see whether I can get the button text to show up
243
  # https://plotly.com/python/reference/layout/updatemenus/
244
 
245
- # this doesn't have any effect
246
- # in either light or dark mode
247
- # `fill` value is rgb(244, 250, 255) still
248
- # when I change this, the browser debugger says that the <text> tag is updating
249
- # not the surrounding <rect>
250
- # also there isn't any change in the <text> tag, it just updates
251
- 'bgcolor': '#00f',
252
-
253
- # This does make the text show up so that's good
254
- 'font': {'color': '#639'},
255
- # And this one works too
256
- 'bordercolor': '#f7b',
257
-
258
- # set all buttons to inactive
259
- # to see whether that gives them all bgcolor
260
- # yep that works
261
- #'active': -1,
262
-
263
- # Or set showactive to False?
264
- # Also works
265
  'showactive': False,
266
-
267
- # they always flash white on mouseover though
268
- # I'm not sure I can change that behavior
269
-
270
- # The actual html "style" text in the page changes when I mouseover the elements
271
- # which makes me think it's not something I can affect
272
-
 
273
  'buttons':[{
274
  'label':'Play',
275
  'method': 'animate',
@@ -277,18 +252,15 @@ def main():
277
  'frame': {'duration':5000},
278
  'transition': {'duration': 2500},
279
  }],
280
- },
281
- # Now this one gets the bgcolor
282
- # and if I click it then the other button gets
283
- # the bgcolor
284
- # so a button only gets bgcolor if it's not "active"
285
- {'label': 'Button 2', 'method':'skip'}
286
  ]
287
  }]
288
  )
289
  )
290
  st.plotly_chart(ani_fig)
291
 
 
 
292
 
293
  if __name__=='__main__':
294
  main()
 
188
  frames = [go.Frame(data=graph_obj) for graph_obj in graph_objs]
189
  # show them with streamlit
190
 
 
 
 
 
 
 
191
 
192
  # This works the way I want
193
  # but the plot is tiny
 
223
  # this one finally set the speed
224
  # no mention of how they figured this out but thank goodness I found it
225
  # https://towardsdatascience.com/basic-animation-with-matplotlib-and-plotly-5eef4ad6c5aa
226
+
227
+ # this also has custom animation speeds in it
228
+ # https://plotly.com/python/custom-buttons/#reference
229
  ani_fig = go.Figure(
230
  data=graph_objs[0],
231
  frames=frames,
232
  layout=go.Layout(
233
  updatemenus=[{
234
  'type':'buttons',
 
 
 
 
 
235
  # https://plotly.com/python/reference/layout/updatemenus/
236
 
237
+ # Always show the background color on buttons
238
+ # streamlit breaks the background color of the active button in darkmode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  'showactive': False,
240
+ # background color of the buttons
241
+ 'bgcolor': '#fff',
242
+ # font in the buttons
243
+ 'font': {'color': '#000'},
244
+ # border color of the buttons
245
+ 'bordercolor': '#000',
246
+
247
+ # Play button
248
  'buttons':[{
249
  'label':'Play',
250
  'method': 'animate',
 
252
  'frame': {'duration':5000},
253
  'transition': {'duration': 2500},
254
  }],
255
+ }
 
 
 
 
 
256
  ]
257
  }]
258
  )
259
  )
260
  st.plotly_chart(ani_fig)
261
 
262
+ st.markdown(f'## {len(FEATS)}')
263
+
264
 
265
  if __name__=='__main__':
266
  main()