Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Dropdown with multiple attribute changes

Is there a way of changing multiple attributes with a single dropdown menu, e.g. changing data and color at the same time? It seems like the args attribute of the updatemenu items only ever accept one attribute change. Using this example, I’ve unsuccessfully tried something along the lines of args=['x',[gold], 'y',[gold]] and args=[ ['x','y'], [gold,gold] ].

countries = ['United States', 'China', 'South Korea', 'Hungary', 'Austraila', 'Canada']
gold   = [10,  8, 4, 4, 4, 0]
silver = [ 8,  3, 2, 1, 0, 1]

curve = Scatter( x=countries, y=gold, name='gold', line = Line( color='#FFD700', width=3 ), )

data = [curve]
layout = Layout(
  title='2016 Summer Olympic Medal Count',
  updatemenus = [
    dict(
      x=-0.05, y=1,
      yanchor='top',
      buttons = [
        dict( args= ['y', [gold]],                    label='Gold',      method='restyle' ),
        dict( args= ['x', [gold ], 'y', [gold]],      label='Gold XY',   method='restyle' ), # <- does not work
        dict( args=[['x', 'y'], [[silver],[silver]]], label='Silver XY', method='restyle' ), # <- does not work
      ],
    )
  ],
)

Yes,

      buttons = [
        dict( args= [dict(x=[gold], y=[gold])],                    label='Gold XY',      method='restyle' ),
      ],

should do the trick - which mimics the plotly.js update object signature (see here).

2 Likes

You’re awesome! Now it works! Thank You!