Search⌘ K
AI Features

Exercise: Custom Buttons and Dropdown Menus

Explore how to add custom buttons and dropdown menus to Plotly charts using the Hang Seng Index data. Understand methods to switch between data traces interactively and customize range sliders for enhanced chart usability.

We'll cover the following...

Exercise

Using the Hang Seng Index dataset, create either a dropdown menu option or a set of buttons to alternate between the Close and the Volume series. Decide whether we should update, relayout, restyle, etc.

Solution

  • An empty figure is created using the go.Figure() function on line 2.

  • A scatter trace is added to the figure using the fig.add_trace() function on line 5. ...