How to make dropdown menu using plotly?

This recipe helps you make dropdown menu using plotly

Recipe Objective

How to make dropdown menu using plotly.

The Dropdown menu is nothing but a part of the menu button, in which it is been displayed on the screen all the time. Here every menu button is being associated with a menu widget and when we click on that button it can show the choices for that menu button. There are four methods possibly in plotly which are used to modify the charts or graphs by using this update menu method which is as follows:

Restyle It will modify the data or data attributes. Relayout It is used to modify the layout attributes. Update It will modify the data and layout attributes. animate used to start or pausing the animation.

Step 1 - Import libraries

import plotly.graph_objects as go import numpy as np

Step 2 - Creat random function

np.random.seed(52) My_Random_xx = np.random.randint(2, 202, 200) My_Random_yy = np.random.randint(2, 202, 200)

Step 3 - Add dropdown and Plot graph

My_plt = go.Figure(data=[go.Scatter( x=My_Random_xx, y=My_Random_yy, mode='markers',) ]) My_plt.update_layout( updatemenus=[ dict( buttons=list([ dict( args=["type", "scatter"], label="Sactter graph", method="restyle" ), dict( args=["type", "bar"], label="Bar Chart", method="restyle" ) ]), direction="down", ), ] ) My_plt.show()

So from the above figure:

The first "My_plt" is about assigning the values to particular variables like we have taken 2 randome variables in which there are random values. The "x" will consist of "My_random_xx" which are having random values and similarly for "y". After that we have created a Dropdown with the help of "Update_layout" in which we have updated the menus and specified the "buttons" as "Sactter graph" and "Bar chart". The Direction is about in which direction the dropdown should be.

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

MLOps Project to Build Search Relevancy Algorithm with SBERT
In this MLOps SBERT project you will learn to build and deploy an accurate and scalable search algorithm on AWS using SBERT and ANNOY to enhance search relevancy in news articles.

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

Recommender System Machine Learning Project for Beginners-2
Recommender System Machine Learning Project for Beginners Part 2- Learn how to build a recommender system for market basket analysis using association rule mining.