Logo image Logo image
  • Overview
  • Getting Started
  • User Guide
  • Gallery
  • Reference Gallery
  • Developer Guide
  • API Reference
  • Releases
  • FAQ
  • About
  • Overview
  • Getting Started
    • Installation
    • Build an app
    • Core Concepts
  • User Guide
    • Overview
    • Components
    • APIs
    • Customization
    • Interact
    • Widgets
    • Parameters
    • Linking
    • Pipelines
    • Templates
    • Performance and Debugging
    • Session state & Callbacks
    • Asynchronous and Concurrent Process
    • Display & Export
    • Running Panel in the Browser with WASM
    • Server Configuration
    • Server Deployment
    • Authentication
    • Django Integration
    • FastAPI Integration
    • Building Custom Components
  • Gallery
    • VTKInteractive
    • VTKSlicer
    • VTKWarp
    • Attractors
    • Gapminders
    • Glaciers
    • Nyc Taxi
    • Portfolio-optimizer
    • Altair Brushing
    • Altair Choropleth
    • Clifford Interact
    • Color Speech Recognition
    • Deckgl Game Of Life
    • Defer Data Load
    • File Download Examples
    • Hvplot Explorer
    • Iris Kmeans
    • Loading Spinner
    • Random Number Generator
    • Save Filtered Df
    • Sync Location
    • Temperature Distribution
    • Xgboost Classifier
    • Stocks Altair
    • Stocks Hvplot
    • Stocks Matplotlib
    • Stocks Plotly
    • Distribution Tabs
    • Dynamic Tabs
    • Plot With Columns
    • Dynamic Plot Layout
    • Dynamic Timeseries Image Analysis
    • Dynamic Ui
    • Dynamic Widget Values
    • Action Button
    • Deck Gl Global Power Plants
    • Download Upload Csv
    • Loading Indicator
    • Param Subobjects
    • Precedence
    • Reactive Plots
    • Reactive Tables
    • Hardware Automation
    • Streaming Bokeh
    • Streaming Indicator
    • Streaming Perspective
    • Streaming Tabulator
    • CanvasDraw
    • LeafletHeatMap
    • MaterialUI
    • Bokeh Property Editor
    • Deck Gl Json Editor
    • Holoviews Glyph Link
    • Plotly Link
    • Vega Heatmap Link
    • MatplotlibStyle
    • PlotlyStyle
    • SeabornStyle
    • VegaAltairStyle
    • DataTable
    • Folium
    • Deck.gl
  • Reference Gallery
    • Alert
    • Audio
    • Bokeh
    • DataFrame
    • DeckGL
    • ECharts
    • Folium
    • GIF
    • HTML
    • HoloViews
    • IDOM
    • IPyWidget
    • JPG
    • JSON
    • LaTeX
    • Markdown
    • Matplotlib
    • PDF
    • PNG
    • Param
    • Perspective
    • Plotly
    • SVG
    • Str
    • Streamz
    • VTK
    • VTKJS
    • VTKVolume
    • Vega
    • Video
    • Accordion
    • Card
    • Column
    • Divider
    • FlexBox
    • GridBox
    • GridSpec
    • GridStack
    • Row
    • Tabs
    • WidgetBox
    • Bootstrap
    • FastGridTemplate
    • FastListTemplate
    • GoldenLayout
    • Material
    • React
    • Vanilla
    • Notifications
    • BooleanStatus
    • Dial
    • Gauge
    • LinearGauge
    • LoadingSpinner
    • Number
    • Progress
    • Tqdm
    • Trend
    • Ace
    • ArrayInput
    • AutocompleteInput
    • Button
    • CheckBoxGroup
    • CheckButtonGroup
    • Checkbox
    • ColorPicker
    • CrossSelector
    • DataFrame
    • DatePicker
    • DateRangeSlider
    • DateSlider
    • DatetimeInput
    • DatetimePicker
    • DatetimeRangeInput
    • DatetimeRangePicker
    • DatetimeRangeSlider
    • Debugger
    • DiscretePlayer
    • DiscreteSlider
    • EditableFloatSlider
    • EditableIntSlider
    • EditableRangeSlider
    • FileDownload
    • FileInput
    • FileSelector
    • FloatInput
    • FloatSlider
    • IntInput
    • IntRangeSlider
    • IntSlider
    • JSONEditor
    • LiteralInput
    • MenuButton
    • MultiChoice
    • MultiSelect
    • PasswordInput
    • Player
    • RadioBoxGroup
    • RadioButtonGroup
    • RangeSlider
    • Select
    • SpeechToText
    • StaticText
    • Tabulator
    • Terminal
    • TextAreaInput
    • TextEditor
    • TextInput
    • TextToSpeech
    • Toggle
    • ToggleGroup
    • VideoStream
  • Developer Guide
    • Testing
    • Developing custom models
  • API Reference
    • io
    • layout
    • pane
      • panel.vtk Package
    • param
    • pipeline
    • template
      • panel.bootstrap Package
      • panel.fast Package
        • panel.grid Package
        • panel.list Package
      • panel.golden Package
      • panel.material Package
      • panel.react Package
      • panel.theme Package
      • panel.vanilla Package
    • widgets
    • viewable
    • util
  • Releases
  • FAQ
  • About
    • Comparisons
On this page
  • Parameters:
    • Core
    • Display
  • Controls

MenuButton#

Download this notebook from GitHub (right-click to download).


import panel as pn
pn.extension()

The MenuButton widget allows specifying a list of menu items to select from triggering events when the button is clicked. Unlike other widgets, it does not have a value parameter. Instead it has a clicked parameter that can be watched to trigger events and which reports the last clicked menu item.

For more information about listening to widget events and laying out widgets refer to the widgets user guide. Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the param user guide. To express interactivity entirely using Javascript without the need for a Python server take a look at the links user guide.

Parameters:#

For layout and styling related parameters see the customization user guide.

Core#

  • clicked (str): The last clicked menu item

  • items (list(tuple or str or None): Menu items in the dropdown. Allows strings, tuples of the form (title, value) or Nones to separate groups of items.

  • split (boolean): Whether to add separate dropdown area to button.

Display#

  • button_type (str): A button theme; should be one of 'default' (white), 'primary' (blue), 'success' (green), 'info' (yellow), or 'danger' (red)

  • disabled (boolean): Whether the widget is editable

  • name (str): The title of the widget


The MenuButton is defined by the name of the button and a list of items corresponding to the menu items. By separating items by None we can group them into sections:

menu_items = [('Option A', 'a'), ('Option B', 'b'), ('Option C', 'c'), None, ('Help', 'help')]

menu_button = pn.widgets.MenuButton(name='Dropdown', items=menu_items, button_type='primary')

pn.Column(menu_button, height=200)

The clicked parameter will report the last menu item that was clicked:

menu_button.clicked

The on_click method can trigger function when button is clicked:

text = pn.widgets.TextInput(value='Ready')

def b(event):
    text.value = f'Clicked menu item: "{event.new}"'
    
menu_button.on_click(b)

pn.Row(menu_button, text, height=300)

The color of the button can be set by selecting one of the available button types:

pn.Column(*(pn.widgets.MenuButton(name=p, button_type=p, items=menu_items) for p in pn.widgets.MenuButton.param.button_type.objects))

Additionally we can move the dropdown indicator into a separate area using the split option:

pn.Row(pn.widgets.MenuButton(name='Split Menu', split=True, items=menu_items), height=200)

If the button itself is clicked in split mode, the clicked property will report the value of the name parameter, i.e. in this case clicking it will set the clicked parameter to 'Split Menu'.

Controls#

The MenuButton widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:

pn.Row(menu_button.controls, menu_button)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).

previous

LiteralInput

next

MultiChoice

© Copyright 2019-2022 Holoviz contributors.

Last updated on 2022-10-05.