Skip to content

Instantly share code, notes, and snippets.

@LinuxIsCool
Created February 7, 2024 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LinuxIsCool/139b00863811c2c264fbb5ee0ab571e0 to your computer and use it in GitHub Desktop.
Save LinuxIsCool/139b00863811c2c264fbb5ee0ab571e0 to your computer and use it in GitHub Desktop.
Hvplot Panel Param example with Accordian

Nice little interactive data widget with accordion example.

import panel as pn
import param as pm
import numpy as np
import pandas as pd
import hvplot.pandas

class SimplePlotExample(pm.Parameterized):
    x = pm.Integer(default=50, bounds=(1, 100))
    
    @pm.depends('x')
    def plot(self):
        # Generate data
        df = pd.DataFrame({
            'x': np.linspace(0, self.x, 100),
            'y': np.linspace(0, self.x, 100)**2
        })
        
        # Plot
        return df.hvplot.line('x', 'y', grid=True, title='y = x^2 Plot')
    
    def view(self):
        view = pn.Column(
            """
            ## Accordion Template Example
            """,
            pn.Accordion(
                ('Plot', pn.panel(self.plot)),
                ('Parameter', pn.Param(self.param, widgets={'x': {'type': pn.widgets.IntSlider, 'name': 'X Value'}})),
            ),
        )
        # Open by default
        view[1].active = list(range(len(view[1])))
        return view

# Create the example instance and serve
example = SimplePlotExample()
example.view()

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment