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

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Build a Text Generator Model using Amazon SageMaker
In this Deep Learning Project, you will train a Text Generator Model on Amazon Reviews Dataset using LSTM Algorithm in PyTorch and deploy it on Amazon SageMaker.

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

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.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker