Panel is designed to make plots interactive. To create an interactive dashboard we need a few elements. We need widgets to allow the user to change the view. We need layouts (Panel objects) to arrange and order visuals. And we need a function(s) that generates the visuals with the input parameters generated from the widgets. And we need the interact function to generate the interactive user interface. The interactive dashboard can be deployed to a html page by using the panel object .show() method.
Notebook display
The interactive dashboards can be showed in your notebook. However, the panel.extension first has to be loaded to initialize the required JavaScript in the notebook context.
pn.extension()
Widgets
Widgets allow the user to change the view of the plot by making selections, clicking buttons and typing into textboxes. Panel supports different type of widgets. Widgets such as radiobuttons, autocomplete input, Date or numeric sliders bounded by a start and end value, Boolean buttons like a toggle, Datetime pickers, Textinputs, Colorpickers and even widgets that interact with dataframes. All the widget options can be found here: https://panel.holoviz.org/user_guide/Widgets.html
Functions
The function should be a function that generates a visual, for instance a plot and that takes arguments as input for creating the visual. It is wise to use default arguments to generate a default visual in case nothing is selected or set by the user
Panel layout objects allow combining plots into a Row, Column, Tabs or a Grid .
There are four main types of Panel layout objects:
Row: A Row arranges a list of components horizontally.
Column: A Column arranges a list of components vertically.
Tabs: A Tabs object lays out a list of components as selectable tabs.
GridSpec: A GridSpec lays out components on a grid.
interactive plot in a row layout
interactive plot in a grid layout
Interact function
The interact function (panel.interact) automatically creates user interface controls for exploring code and data interactively. It combines the function with the input by calling the interact method with the function and input.
# creating an interactive user interface object
explorer, flower_plot = pn.interact(flowers_plot, x=columns, y=columns)
# create a row with two columns, the x,y explorer and the plot
row = pn.Row(pn.Column("Iris Explorer", explorer),
flower_plot)
#create a grid
flowergrid = pn.GridSpec(sizing_mode='stretch_both', max_height=800)
flowergrid[0,0] = explorer
flowergrid[0,1] = flower_plot
flowergrid[1,0] = pn.pane.DataFrame(flowers)
flowergrid[1,1] = "image.jpg"